Triggering Jenkins builds on new tags and commits

We use the Git plugin: https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

Currently, through webhooks, we run the Jenkins build whenever a change is ported to GitHub. Now we want to run the same assembly when a new tag is added. So, we have two launch conditions:

  • Code change ported to github
  • Tag created

If we try to correct the mention in this thread, the assembly will begin only for tags. jenkins trigger build if new tag released

How can we do this for both scenarios?

Question No. 02: How can we get the tag name inside the Jenkins assembly, is there an environment variable for it.

+4
source share
2 answers

Try using the Jenkins GitHub Plugin

It works great for us both for the created tag and for the change.

For tags, you can use the environment variable $ {GIT_BRANCH} , it must contain a tag in the format origin / tags /% tag%

0
source

4 Step of the process:

  • Commit Code: git commit -m "Some meaningful message"
  • Create tag
    • To enter the stage: git tag -a release_stage_<meaningful tag>
    • To free a file: git tag -a release_production_<meaningful tag>
  • Push Tag Click Tag: git push origin release_stage_<same_meaningful_tag>
  • Push commit git push origin <branch_name>

Jenkins File:

stage('Checkout Project') properties([pipelineTriggers([[$class: 'GitHubPushTrigger']])]) checkout scm git_branch = env.BRANCH_NAME git_branch_to_release = env.BRANCH_NAME git_tag = sh returnStdout: true, script: 'git tag -l --points-at HEAD'

//And now you can use to do anything with tags

`` ``

if(currentBuild.result=='SUCCESSFUL' || currentBuild.result=='SUCCESS' || currentBuild.result == null)
        {
            if (git_tag.contains('release_stage') || git_tag.contains('release_production'))
            {
            // Do anything which you want to do with tags
            }
}

`` ``

0
source

Source: https://habr.com/ru/post/1661966/


All Articles