stage ('Build image') {
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'user', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh "tempPass=\$(aws ecr get-login-password --region us-west-2)"
echo 'Hello------------------'
echo "${tempPass}"
echo 'Hello AFTER------------------'
}
}
}
Exception : groovy.lang.MissingPropertyException: No such property: pass for class: groovy.lang.Binding
我也试过 echo "$tempPass" 但没有用。
我也试过这个,但变量值为空。
script {
tempPass=sh(script: "aws ecr get-login-password --region us-west-2")
}
有人可以帮忙吗?
答案 0 :(得分:1)
您需要从 sh
步骤返回 returnStatus
或 returnStdout
https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script
例如
latest_tag = sh(script: "aws ecr get-login-password --region us-west-2", returnStdout: true).trim()