我是新手,这就是为什么我寻求您的帮助。 我不明白为什么我的构建失败,但这是问题所在:
我想对变量输出“ sofia”进行if陈述。
因此,如果kubernetes == sofia这样做,否则...其他
但是,当变量为空时,它给了我:
groovy.lang.MissingPropertyException: No such property: kubernetes for class: groovy.lang.Binding
完成:失败
这是我的代码:
stage('Refresh AWS Environment') {
environment {
BN = sh(script: "echo $GIT_BRANCH | cut -d '/' -f 2", returnStdout: true).trim()
BRANCH_RELEASE = sh(script: "find synchr -type f -name gradle.properties -exec grep release {} + | cut -d= -f2", returnStdout: true).trim()
COMMIT = sh(script: "git log -1 --date=iso | grep ^commit | cut -d ' ' -f 2", returnStdout: true).trim()
COMMIT_DATE = sh(script: "git log -n 1 --pretty='format:%cd' --date=format-local:'%Y%m%d-%H%M%S'", returnStdout: true).trim()
BUILD_TIME = sh(script: "date '+%Y/%m/%d-%H:%M:%S'", returnStdout: true).trim()
awstag = "$BN-$COMMIT_DATE"
kubernetes = sh(script: "grep 'sofia' registry/environments/${BN}.yaml | cut -d : -f2", returnStdout: true).trim()
namespace = sh(script: "grep 'namespace' registry/environments/${BN}.yaml | cut -d : -f2", returnStdout: true).trim()
}
steps {
script {
withCredentials([usernamePassword(credentialsId: 'apiuser', usernameVariable: 'username', passwordVariable: 'token')]) {
if (kubernetes == 'sofia') {
sh "curl --insecure -g --user \"$username:$token\" -F \"nameSpace=$namespace\" -F \"tag=$awstag\" https://192.168.20.223:8443/job/Ci-refresh//buildWithParameters"
sh "sleep 25"
def response
timeout(90) {
waitUntil {
response = sh(
script: "curl --insecure --silent -g --silent --user \"$username:$token\" https://192.168.20.223:8443/job/Ci-refresh/lastBuild/api/json | grep -i success",
returnStatus: true
)
return (response == 0)
}
}
if (response != 0) {
build.result = 'ERROR'
}
} else {
try {
build job: 'kubernetes-management/ci-refresh', parameters: [[$class: 'StringParameterValue', name: 'nameSpace', value: projectYaml?.namespace], [$class: 'StringParameterValue', name: 'tag', value: awstag]]
} catch (Exception e) {
println "CI not performed for ${BN} ${e.message}"
}
}
}
}
}
}