以下是我在管道文件中的示例代码
node('ubuntu') {
stage ('build') {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'terraform', accessKeyVariable: 'aws_access_key', secretKeyVariable: 'aws_secret_key']]) {
def command1 = $/"/packer/packer build -var 'aws_ami_image=${ami_image}' -var 'aws_access_key=${aws_access_key}' -var 'aws_secret_key=${aws_secret_key}' /packer/ubuntu/dummy-deploy.json"/$
res = sh(returnStdout: true, script: "${command1}")
sh("echo ${res}")
}
}
}
我收到文件未找到错误。远程节点和主站有/ packer / packer和/packer/ubuntu/dummy-deploy.json
[dummy] Running shell script
+ '/packer/packer build -var '\''aws_ami_image=******'\'' -var '\''aws_access_key=****'\'' -var '\''aws_secret_key=****'\'' /packer/ubuntu/dummy-deploy.json'
/jenkins/workspace/dummy@tmp/durable-5492c9fb/script.sh: line 2: /packer/packer build -var 'aws_ami_image=ami-*****' -var 'aws_access_key=****' -var 'aws_secret_key=****' /packer/ubuntu/dummy-deploy.json: No such file or directory
脚本返回退出代码1
答案 0 :(得分:0)
抱歉混合声明性和脚本化的管道。我从脚本管道开始,最后是声明性的。
pipeline {
agent { node { label 'linux' } }
// Define Variables
environment {
...
...
}
stages {
stage ('plan') {
steps {
script {
....
}
}
}
}
}
答案 1 :(得分:-1)
添加脚本{}块解决了问题
node('ubuntu') {
stage ('build') {
script {
}
}
}