Deploying from a Git Tag -- buildingTag
https://notesfromthelifeboat.com/post/deploying-from-a-git-tag/
If you want to evaluate your changes in the staging environment automatically via a smoketest script, and push to production on a successful test, you don’t need a parameter at all; you can set the
ENVIRONMENT
for each stage in the pipeline:
pipeline { agent { label 'myLabel' } environment { GIT_TAG = sh(returnStdout: true, script: 'git describe --always').trim() } stages { stage("Checkout") { steps { checkout scm } } stage("Test") { steps { sh('make test') } } stage("Deploy to Staging") { when { buildingTag() } environment { ENVIRONMENT = 'staging' } steps { sh('make deploy') } } stage("Smoketest") { steps { sh('make smoketest') } } stage("Deploy to Production") { when { buildingTag() } environment { ENVIRONMENT = 'production' } steps { sh('make deploy') } } } }
When using tags -- tag
https://www.jenkins.io/blog/2018/05/16/pipelines-with-git-tags/
One common pattern for automated releases I have seen and used relies on Git tags as the catalyst for a release process. The immutable nature of releases and the immutable nature of tags can definitely go hand in hand, but up until few months ago Jenkins Pipeline was not able to trigger effectively off of Git tags.
pipeline { agent any stages { stage('Build') { steps { sh 'make package' } } stage('Test') { steps { sh 'make check' } } stage('Deploy') { when { tag "release-*" } steps { echo 'Deploying only because this commit is tagged...' sh 'make deploy' } } } }
when
https://www.cnblogs.com/rxysg/p/15682060.html
buildingTag :如果pipeline所执行的代码被打了tag,则执行
when {
buildingTag()
}
tag:如果pipeline所执行的代码被打了tag,且tag名称符合规则,则执行。如果tag的参数为空,即tag ( ),则表示不论tag名称是什么都执行,与buildingTag的效果相同。
when {
tag "release-*"
}
tag条件支持comparator参数,支持的值如下。
EQUALS:简单的文本比较when {
tag pattern "release-3.1", comparator: "EQUALS"
}
GLOB(默认值) :Ant风格路径表达式。由于是默认值,所以使用时一般省略。
when {
tag pattern "release-*", comparator: "GLOB"
}
REGEXP∶正则表达式
when {
tag pattern "release-\\d+", comparator: "REGEXP"
}
Configure the Jenkins project
https://comquent.de/de/de-triggering-jenkins-when-new-tags-are-created/
There are two changes that need to be applied in the Jenkins server. We should enable the Poll SCM build trigger in our pipeline job setting and enter a Schedule. This way, Jenkins will be able to check our project in Bitbucket for any changes. Then in the SCM section on the pipeline job configuration panel, we can enter the following settings:
- Refspec: +refs/tags/*:refs/remotes/origin/tags/*
- Branch: specifier **/tags/**
That’s all, the configuration is done and now it is time to check if this is working.
标签:tags,continuous,when,sh,tag,steps,deployment,Jenkins,stage From: https://www.cnblogs.com/lightsong/p/17066524.html