[英]Using global variables to push tags to Git in Jenkins Pipeline
I cannot wrap my head around using global variables in Git commands. 我无法在Git命令中使用全局变量来解决问题。 I have the following code:
我有以下代码:
stage('Publish to GIT') {
steps {
bat 'git push -v origin website-0.${env.BUILD_NUMBER}'
}
}
BUILD_NUMBER is a global variable used in Jenkins but I cannot get it to resolve. BUILD_NUMBER是Jenkins中使用的全局变量,但我无法解决它。 I also tried using Powershell but to no avail.
我也尝试使用Powershell,但无济于事。 I also tried
${BUILD_NUMBER}
$BUILD_NUMBER
but without success. 我也尝试了
${BUILD_NUMBER}
$BUILD_NUMBER
但没有成功。
Any ideas what I am doing wrong? 有什么想法我做错了吗? Thanks in advance!
提前致谢!
Regards 问候
when you are using pipelines be notted that it is groovy , which means you have to follow code/syntax rulles. 当您使用管道时,请注意它是groovy的,这意味着您必须遵循代码/语法规则。 in your snippet the only mistake is that you are using ' in stead of " which means follwing: usage of ' - whatever is inside is treated as String, so ${env.BUILD_NUMBER} wont be executed usage of " - whatever is inside is teated as String, apart from ${SOMETHING} which will be executed and changed with the value of the var
在您的代码段中,唯一的错误是您正在使用'代替“,这意味着以下:使用'-内部的任何内容都视为String,因此$ {env.BUILD_NUMBER}不会被执行使用”-内部的所有内容除$ {SOMETHING}之外,将其作为String进行处理,该$ {SOMETHING}将通过var的值执行和更改
having that in mind you have to have following instead what you have now: 考虑到这一点,您必须遵循以下内容,而不是现在拥有的内容:
stage('Publish to GIT') {
steps {
sh|bat "git push -v origin website-0.${env.BUILD_NUMBER}"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.