Triggering Jenkins build on both new tags & commits

北战南征 提交于 2019-12-01 06:07:24

4 Step Process:

  1. Commit Code : git commit -m "Some meaningful message"
  2. Create a tag
    • To release to stage : git tag -a release_stage_<meaningful tag>
    • To release to prod : git tag -a release_production_<meaningful tag>
  3. Push Tag Push the tag : git push origin release_stage_<same_meaningful_tag>
  4. 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
            }
}

```

Try using Jenkins GitHub Plugin

It works perfectly well for us for both tag created and changes pushed.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!