Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

Escaping single quotes in Jenkins Execute Shell script block

I want to execute aws-cli command through Jenkins Execute Shell script. But I am facing issue with double quotes and single quotes. Here is the command I want to execute

aws cloudformation create-stack --template-url templates.url --parameters ParameterKey=TagName,ParameterValue='My Test Job'

But when I execute my Jenkins job it removes singles quotes and my command becomes

aws cloudformation create-stack --template-url templates.url --parameters ParameterKey=TagName,ParameterValue=My Test Job

How can I escape single quotes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you should share a more complete part of the pipeline so we can understand how are you running that command. I will asume the simple case that your command is in a sh step in a stage. In this case you must escape the characters .

stage('Deploy to Server') {
      steps{
        sh "aws cloudformation create-stack --template-url templates.url --parameters ParameterKey=TagName,ParameterValue='My Test Job'"
      }
}

Bear in mind the the log output will not give you the exact command . you should use an echo or a logging function to actually see the command correctly. Here is a page that helped me a lot in manipulating the strings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...