GithubHelp home page GithubHelp logo

trigger pipeline by git tag about erda HOT 2 CLOSED

JdaieLin avatar JdaieLin commented on September 3, 2024
trigger pipeline by git tag

from erda.

Comments (2)

JdaieLin avatar JdaieLin commented on September 3, 2024

Since refName is possible to be a git tag or a branch name, some modification might be needed in /modules/dop/endpoints/release.go

        isTag := req.Content.IsTag
	refName := ""
	branchName := ""
	if isTag {
		refName = strings.TrimPrefix(req.Content.Ref, "refs/tags/")
		// TODO: get branchName by tag name from gittar
                // git branch -r --contains <tag> 
	} else {
		refName = strings.TrimPrefix(req.Content.Ref, "refs/heads/")
		branchName = refName
	}

	// 从 gittar 获取 pipeline.yml
	strPipelineYml, err := e.pipeline.FetchPipelineYml(req.Content.Repository.URL, refName, apistructs.DefaultPipelineYmlName)
	if err != nil {
		logrus.Errorf("failed to fetch pipeline.yml from gittar, req: %+v, (%+v)", req, err)
		return apierrors.ErrReleaseCallback.InternalError(err).ToResp(), nil
	}

	pipelineYml, err := pipelineyml.New([]byte(strPipelineYml))
	if err != nil {
		logrus.Errorf("failed to parse pipeline.yml yaml:%v \n err:%v", pipelineYml, err)
		return apierrors.ErrReleaseCallback.InternalError(err).ToResp(), nil
	}

	// 应用级设置
	if pipelineYml.Spec().On != nil && pipelineYml.Spec().On.Push != nil {
		// 满足 branches规则 或者 tags规则 都可以通过
		if (!isTag && !diceworkspace.IsRefPatternMatch(refName, pipelineYml.Spec().On.Push.Branches)) {
			return httpserver.OkResp("")
		}
		if (isTag && !diceworkspace.IsRefPatternMatch(refName, pipelineYml.Spec().On.Push.Tags)) {
			return httpserver.OkResp("")
		}
	} else {
		// 项目级设置
		validBranch := diceworkspace.GetValidBranchByGitReference(refName, rules)
		if !validBranch.IsTriggerPipeline {
			return httpserver.OkResp("")
		}
	}

	// 创建pipeline流程
        // TODO: use branchName instead of refName
	reqPipeline := &apistructs.PipelineCreateRequest{
		AppID:              uint64(req.Content.Repository.ApplicationID),
		Branch:             branchName, 
		Source:             apistructs.PipelineSourceDice,
		PipelineYmlSource:  apistructs.PipelineYmlSourceGittar,
		PipelineYmlContent: strPipelineYml,
		AutoRun:            true,
		UserID:             req.Content.Pusher.ID,
	}

from erda.

Muzry avatar Muzry commented on September 3, 2024

PR #959 has already Merged,close this issue

from erda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.