Issue
I'm running Cypress test suites using Jenkins. I have created Execute shell
scripts that run the entire suite & it's working nicely like so:
cd frontend
node --version
yarn install
echo '{ "USERNAME": "redacted-harcoded-username", "PASSWORD": "redacted-harcoded-password", BASE_URL: "redacted-harcoded-baseURl" }' > cypress.env.json
yarn cypress:run
However, I passed some Jenkins's parameters like so:
cd frontend
node --version
yarn install
echo `{ "USERNAME": ${USERNAME}, "PASSWORD": ${PASSWORD}, BASE_URL: ${BASE_URL} }` > cypress.env.json
yarn cypress:run --spec ${SPECS_TO_RUN}
Unfortunately, when using echo
I need to switch the single quotes to be able to pass the dynamic values like so:
echo `{ "USERNAME": ${USERNAME}, "PASSWORD": ${PASSWORD}, BASE_URL: ${BASE_URL} }` > cypress.env.json
This is causing my command to fail & give me an error that my json
file is not valid. Any workarounds to fix this issue?
Solution
I was able to find the solution with this combination of bash escaping:
echo { \"USERNAME\": \"${USERNAME}\", \"PASSWORD\": \"${PASSWORD}\", \"BASE_URL\": \"${BASE_URL}\" } > cypress.env.json
Answered By - Manuel Abascal
Answer Checked By - David Marino (JavaFixing Volunteer)