I am trying to capture the response of an http request in a variable. The following question gave me the perfect solution to this (How to evaluate http response codes from bash/shell script?). When I execute this command locally
response=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:8082/url)
echo $response
It gives me the wanted http code (e.g. 400). However in Jenkins I execute the same command, but it gives me an empty response:
sh '''#!/bin/bash
DOCKER_RESPONSE=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:8002/route?json={})
while [[ $DOCKER_RESPONSE != 200 ]]
do
sleep 1
echo "$DOCKER_RESPONSE"
DOCKER_RESPONSE=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:8002/route?json={})
done
'''