触发Jenkins建立在新标签和新标签之上。提交 [英] Triggering Jenkins build on both new tags & commits
问题描述
我们正在使用Git插件: https://wiki.jenkins- ci.org/display/JENKINS/Git+Plugin
目前,通过webhooks,只要将更改推送到GitHub,我们就会启动Jenkins构建。现在,我们希望在添加新标签时触发相同的构建。所以我们有两个触发条件: 如果我们在此线程中尝试修复提及,那么构建仅针对标记开始。 如果发布新标签,jenkins会触发构建 我们如何在两种情况下都做到这一点? 问题#02:我们如何在Jenkins版本中获取标签名称,是否有任何环境变量。 4步骤过程: Jenk ('Checkout Project') ``` We are using the Git Plugin : https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin 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 : 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 ? Question # 02 : How can we get the tag name inside a Jenkins build, is there any environment variable for it. 4 Step Process: Jenkins File: ``` ``` 这篇关于触发Jenkins建立在新标签和新标签之上。提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $ ol
代码更改被推送到GitHub
git commit -m一些有意义的消息
>
git tag -a release_stage_<有意义的标签>
git tag -a release_production_<有意义的标签>
git push origin release_stage_< same_meaningful_tag>
git push origin< branch_name>
properties([pipelineTriggers([[$ class:''))
$ b $ stage GitHubPushTrigger']])])
checkout scm
git_branch = env.BRANCH_NAME
git_branch_to_release = env.BRANCH_NAME
git_tag = sh returnStdout:true,script:'git tag -l - 点在HEAD'
//现在您可以使用
$ p
$ b $ $ p $ if(currentBuild.result =='SUCCESSFUL'|| currentBuild.result =='SUCCESS'|| currentBuild.result == null)
{
if(git_tag.contains('release_stage')|| git_tag.contains('release_production'))
{
//执行任何操作你想用标签
}
}
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>
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
}
}