jenkins pipeline sh 添加新行 [英] jenkins pipeline sh adding new line

查看:57
本文介绍了jenkins pipeline sh 添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的管道 sh 块:

 sh "set +e; /terraform/terraform plan -var aws_access_key=${aws_access_key} -
 var aws_secret_key=${aws_secret_key} -var aws_ami=${ami_id} -var 
 aws_instance_type=${instance_type} -var aws_elb_security_group=${elb_sg} -var 
 aws_ec2_security_group=${ec2_sg} -detailed-exitcode; echo $? > status"
              exitCode = readFile('status').trim()
              echo "Terraform Plan Exit Code: ${exitCode}"

输出:

+ set +e
+ /terraform/terraform plan -var aws_access_key=**** -var aws_secret_key=**** -var aws_ami=ami-xxxxxxx
+ -var aws_instance_type=t2.medium -var aws_elb_security_group=sg-xxxx
/terraform/selectdev/int/mp-frontend@tmp/durable-6c57c14c/script.sh: line 3: -var: command not found
+ -var aws_ec2_security_group=sg-axxx
 /terraform/selectdev/int/mp-frontend@tmp/durable-6c57c14c/script.sh: line 4: -var: command not found
+ -detailed-exitcode
/terraform/selectdev/int/mp-frontend@tmp/durable-6c57c14c/script.sh: line 5: 
 -detailed-exitcode: command not found
+ echo 127

我不确定为什么要在命令中添加新行,如果我使用 sh '' 之类的单引号,则变量为空白.我做错了什么?

I'm not sure why new line is being added to the command and If I do single quotes like sh '', variables are blank. what am I doing wrong ?

我尝试像下面那样做,但它也添加了新行

I tried to do like below but it too adding new lines

def command = $/....../$
res = sh(returnStdout: true, script: command)

推荐答案

我使用的变量来自其他阶段,并且有新行..必须使用.trim()

The variables I'm using are from other stages and have new line.. had to use .trim()

这篇关于jenkins pipeline sh 添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆