3

I know that there are a few questions with answers on how to do this, however I still can't seem to get my scenario to work when wrapping my variable in double quotes.

I am executing a curl request to obtain a valid crumb in Jenkins so that I can then execute a job via a POST request.

So at the moment I get response like Password Invalid as the variable ${USER_TOKEN} is not recognised

echo "The USER TOKEN is " ${USER_TOKEN} # This outputs 123456789 for example
CRUMB=$(curl -s 'http://jenkins:${USER_TOKEN}@localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField, ":",//crumb)')

If I hardcode the USER_TOKEN then this will work but I obviously wanted to avoid that.

How can I execute this curl command and pass in the USER_TOKEN?

Updates

If I surround ${USER_TOKEN} with double quotes I still get the same error.

CRUMB=$(curl -s 'http://jenkins:"${USER_TOKEN}"@localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField, ":",//crumb)')

And if I surround the curl request with double quotes I get

Invalid Xpath expression, contact(//crumbRequestField,:,//crumb)
Unexpected ':'
1
  • Why can't you doublequote it? curl -s 'http://jenkins:'"${USER_TOKEN}"'@localhost? Commented Sep 26, 2016 at 7:58

2 Answers 2

2

You need to double quote a string that contains double quotes. This is one way:

CRUMB=$(curl -s "http://jenkins:${USER_TOKEN}@localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField, "'":"'",//crumb)")
Sign up to request clarification or add additional context in comments.

Comments

0

Try it this way

CRUMB=$(curl -s "http://jenkins:"${USER_TOKEN}"@localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField, \":\",//crumb)")

If you want an variable expanded in your string than the whole string have to be surrounded with double quote. Single quotes prevent any bash evaluation. Also you have to escape any double quotes in the whole string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.