Issue
Searching stackoverflow and other google searches did not satisfy my question about assigning bash variable inside curl for the whole purpose of accessing jenkins API.
This is my simple script to access Jenkins API and it already goes wrong here:
JENKINS_USER=myUser
TOKEN=myToken
DOCK=myDock
HOST=localhost
PORT=8080
BASE_URL=https://$JENKINS_USER:$TOKEN@$HOST:$PORT/view/all/job/myProject/api/
curl -g -k ${BASE_URL}
Output from bash:
user@c012311:/mnt/c/Users/User/Desktop$ ./myScript.sh
./myScript.sh: line 6: $'\r': command not found
./myScript.sh: line 11: $'\r': command not found
curl: (3) URL using bad/illegal format or missing URL
I tried accessing my variables like so:
- \"$TOKEN\"
- ${TOKEN}
- '$TOKEN'
Yet the results are the same.
The results are preventing me from furthere progression my script for filtering my jenkins builds:
BUILD_NR=$BASE_URL/xml&xpath=//artifact/relativePath[contains(text(),$DOCK)])
And furthere more using those assigned variables inside other variables:
ARTIFACT=$BUILD_NR/[...]
How do I correctly assign variables using bash and curl?
Solution
Thanks to @shellter for providing an answer for my problem.
I fixed this by adding double quotes to all variables like so:
BASE_URL="https://"${JENKINS_USER}":"${TOKEN}"@"${HOST}":"${PORT}"/view/all/job/myProject/api/"
Furthemore - by executing dos2unix myScript
I dont get those annoying outputs anymore:
./myScript.sh: line 6: $'\r': command not found
./myScript.sh: line 11: $'\r': command not found
Answered By - Delice