我们正在使用Git插件:https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
目前,通过webhooks,只要将更改推送到GitHub,我们就会启动Jenkins构建。现在,我们希望在添加新标记时触发相同的构建。所以我们有两个触发条件:
如果我们在此线程中尝试修复提及,则构建仅针对标记启动。 jenkins trigger build if new tag is released
我们怎样才能在两种情况下都这样做?
问题#02:如何在Jenkins构建中获取标记名称,是否有任何环境变量。
答案 0 :(得分:2)
4步骤:
git commit -m "Some meaningful message"
git tag -a release_stage_<meaningful tag>
git tag -a release_production_<meaningful tag>
git push origin release_stage_<same_meaningful_tag>
git push origin <branch_name>
Jenkins文件:
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
}
}
```
答案 1 :(得分:0)
对于我们标记创建和更改推送都非常有效。
对于可以使用 $ {GIT_BRANCH} 环境变量的标记,它应包含 origin / tags /%tag%格式的标记