[英]Not getting version number plugin value in Jenkins
I am using declarative pipeline syntax for my pipeline job in Jenkins for my project. 我在Jenkins中为我的项目的管道作业使用了声明式管道语法。 I wanted to use
我想用
pipeline {
agent any
environment {
VERSION = VersionNumber projectStartDate: '', versionNumberString: '${BUILD_YEAR}.${BUILD_MONTH}.${BUILDS_TODAY}.${BUILD_NUMBER}', versionPrefix: 'v1.', worstResultForIncrement: 'SUCCESS'
}
stages {
stage('Version Update'){
steps{
echo '${VERSION}'
writeFile file: 'version.ini', text: '%VERSION%'
}
}
}
}
I tried ${VERSION},%VERSION to print the version number, but it always print whats inside the echo, text inside writeFile step. 我试过$ {VERSION},%VERSION来打印版本号,但是它总是打印回显内的内容,writeFile步骤内的文本。 (eg %VERSION%)
(例如,%VERSION%)
I am able to see the version in the side menu with the format I used. 我可以在侧面菜单中以所使用的格式查看版本。
In groovy,strings that use single quotes '
don't get interpolated . 在常规中,使用单引号
'
字符串不会被插值 。 You should use double quotes instead, and use $
in front of each variable you want to get replaced (if you want to keep a $
in a string you need to escape it with \\
). 您应该改为使用双引号,并在要替换的每个变量前面使用
$
(如果要将$
保留在字符串中,则需要使用\\
对其进行转义)。
For writeFile
it's a pipeline command, so it runs as groovy on the jenkins master and not on a build node. 对于
writeFile
来说,这是一个管道命令,因此它在詹金斯主服务器上而不是在构建节点上以常规方式运行。 That's why you need to treat it as such (double quotes and $
). 这就是为什么您需要这样对待它(双引号和
$
)。 pipeline { agent any 管道{代理任何
environment {
VERSION = VersionNumber projectStartDate: '', versionNumberString: "${BUILD_YEAR}.${BUILD_MONTH}.${BUILDS_TODAY}.${BUILD_NUMBER}", versionPrefix: 'v1.', worstResultForIncrement: 'SUCCESS'
}
stages {
stage('Version Update') {
steps {
echo "${VERSION}"
writeFile file: 'version.ini', text: "$VERSION"
}
}
}
}
Note: I don't use the version number plugin, so I wasn't able to test this exact code 注意:我不使用版本号插件,因此无法测试此确切代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.