I am working on a Tekton task that makes a cURL command request, extracts a response to a JSON file, and then extracts attributes from that JSON. I have noticed a behavior with my task that even if my cURL command fails, it does not fail the task.
Below is my cURL command. When the cURL command fails while getting the pull number from the response, it does not fail my Tekton task:
curl -X GET -H "Authorization: token ${GIT_API_TOKEN}" --url "https://github.ford.com/api/v3/repos/${gitOrgName}/${gitRepoName}/commits/$GIT_COMMIT_ID/pulls" -o sonarScanResponse.json
export pullNumber=$(jq -j '.[0].number' sonarScanResponse.json)
On searching in Google, I found a suggestion to add the following snippet. Unfortunately, this is also not working:
curl -X GET -H "Authorization: token ${GIT_API_TOKEN}" -w "%{http_code}" --url "https://github.ford.com/api/v3/repos/${gitOrgName}/${gitRepoName}/commits/$GIT_COMMIT_ID/pulls" -o sonarScanResponse.txt
# Check HTTP status code
if [ $(cat sonarScanResponse.txt) != "200" ]; then
echo "HTTP status code is not 200"
exit -1
fi
sonarScanResponse=$(cat sonarScanResponse.txt | jq .)
export pullNumber=$(jq -j '.[0].number' sonarScanResponse.json)
I am getting too many arguments error at this line if [ $(cat sonarScanResponse.txt) != "200" ]; then
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 18821 100 18821 0 0 62946 0 --:--:-- --:--:-- --:--:-- 62946 200/usr/bin/script.sh: line 72: [: too many arguments
Can someone help me get this resolved?