I am creating a release definition in VSTS where i need to fetch just the external ip of the service which is getting deployed using Shell Script. I am able to do it from command line but not from VSTS release definition. I have got the JSON stored in a variable which consists of the IP. I need to fetch the IP from this JSON.
Or let me know if their is any command for kubernetes which will return just the external ip of the deployed services and not any other information.
Try this code:
function readJson {
UNAMESTR=`uname`
if [[ "$UNAMESTR" == 'Linux' ]]; then
SED_EXTENDED='-r'
elif [[ "$UNAMESTR" == 'Darwin' ]]; then
SED_EXTENDED='-E'
fi;
VALUE=`grep -m 1 "\"${2}\"" ${1} | sed ${SED_EXTENDED} 's/^ *//;s/.*: *"//;s/",?//'`
if [ ! "$VALUE" ]; then
echo "Error: Cannot find \"${2}\" in ${1}" >&2;
exit 1;
else
echo $VALUE ;
fi;
}
NAME=`readJson package.json name` || exit 1;
# $NAME is "sample-project"
You can output the variable value to a JSON file by calling echo {variable} > test.json
.
Assuming you have a service of type LoadBalancer
:
kubectl get svc <your_service> -ao jsonpath='{..ip}'