我有以下Jenkinsfile脚本块。执行作业时,最终用户勾选几个复选框(扩展选择参数),所选值将转到ReposToUpdate
和npmDependencies
。
然后,在执行Jenkinsfile时,我收到以下错误:
java.lang.NullPointerException:无法在null对象上获取属性“$ repoName”
Jenkinsfile的大部分都可以被忽略(它与目标有关,而不是上面提到的问题)。
def repoList = ReposToUpdate.tokenize(",");
def moduleList = npmDependencies.tokenize(",");
pipeline {
agent {
label '****'
}
stages {
stage ("Update package.json") {
steps {
script {
for (String repoName : repoList) {
sshagent (credentials: ['****']) {
sh '''
git clone -b master git@****.com:****/${repoName}.git
cd ${repoName}
stat -t . > folderStat1.txt
'''
for (String moduleName : moduleList) {
sh '''
cd ${repoName}
ncu -u -f "${moduleName}"
stat -t . > folderStat2.txt
'''
}
def folderStat1 = readFile('folderStat1.txt').trim()
def folderStat2 = readFile('folderStat2.txt').trim()
if (folderStat1 == folderStat2) {
slackSend (
color: '#199515',
message: "$JOB_NAME: <$BUILD_URL|Build #$BUILD_NUMBER> ${repoName}: Common code dependencies match the latest package versions."
)
}
else {
sh '''
cd ${repoName}
git config --global user.name "****"
git config --global user.email ****
git commit -am 'Bump common packages version number [ci skip]'
git push origin master
cd ..
rm -rf ${repoName}
'''
slackSend (
color: '#199515',
message: "$JOB_NAME: <$BUILD_URL|Build #$BUILD_NUMBER> ${repoName}: Common code dependencies successfully updated to the latest package versions."
)
}
}
}
}
}
}
}
post {
failure {
slackSend (
color: '#F01717',
message: "$JOB_NAME: <$BUILD_URL|Build #$BUILD_NUMBER>, Update failed. Review the build logs."
)
}
}
}
答案 0 :(得分:1)
单引号无法访问变量
sh """ ${variable} """ vs sh ''' ${variable} '''
http://mrhaki.blogspot.com/2009/08/groovy-goodness-string-strings-strings.html
https://blog.art-of-coding.eu/single-or-double-quotation-marks-in-groovy/