在新标签和新标签上触发 Jenkins 构建提交 [英] Triggering Jenkins build on both new tags & commits
问题描述
我们正在使用 Git 插件:https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
We are using the Git Plugin : https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
目前,只要将更改推送到 GitHub,我们就会通过 webhook 启动 Jenkins 构建.现在我们想在添加新标签时触发相同的构建.所以我们有两个触发条件:
Currently, via webhooks we start a Jenkins build whenever a change is pushed to GitHub. Now we want to trigger the same build when a new tag is added. So we have two triggering conditions :
- 将代码更改推送到 GitHub
- 创建了一个标签
如果我们尝试此线程中提到的修复,则构建仅针对标签开始.jenkins 在新标签发布时触发构建
If we try the fix mention in this thread then the builds start only for tags. jenkins trigger build if new tag is released
我们如何在这两种情况下做到这一点?
How can we do it for both scenarios ?
问题 #02:我们如何在 Jenkins 构建中获取标签名称,是否有任何环境变量.
Question # 02 : How can we get the tag name inside a Jenkins build, is there any environment variable for it.
推荐答案
4步流程:
- 提交代码:
git commit -m "一些有意义的消息"
- 创建标签
- 发布到舞台:
git tag -a release_stage_<有意义的标签>
- 发布到产品:
git tag -a release_production_<有意义的标签>
- 发布到舞台:
Jenkins 文件:
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
}
}
这篇关于在新标签和新标签上触发 Jenkins 构建提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!