我没有找到在sh脚本中使用Jenkins提供的BUILD_NUMBER的方法。 我已经阅读了一些类似问题的答案,但没有什么帮助。
node {
echo "Build number 1 $BUILD_NUMBER"
// output ok
stage('stage1') {
echo "Build number 2 $BUILD_NUMBER"
// output ok
def BUILD_NUMBER = "$BUILD_NUMBER"
withCredentials([sshUserPrivateKey(credentialsId: 'github-rsa-key', variable: 'RSAKEY')]) {
echo "Build number 3 " + BUILD_NUMBER
// output ok
echo "Build number 4 $BUILD_NUMBER"
// output ok
// -----------------
sh 'echo $BUILD_NUMBER' // NullPointer
sh "echo $BUILD_NUMBER" // NullPointer
sh "echo \$BUILD_NUMBER" // NullPointer
sh "echo BUILD_NUMBER" // NullPointer
withEnv(["BUILD_NUMBER=BUILD_NUMBER"]) {
sh "echo $BUILD_NUMBER" // NullPointer!!
}
env.BUILD_NUMER = "$BUILD_NUMBER"
sh "echo $BUILD_NUMBER" // NullPointer
sh "echo ${env.BUILD_NUMBER}" // NullPointer
}
}
}