I write this function
def docker_images(image_name,image_tag){
def curl_image_exists_status_code =
curl_image_exists_status_code=sh (
script:""" docker login -u XXXXX -p $$$ 2> /dev/null 1>/dev/null
docker pull XXXXX/'${image_name}':'${image_tag}' > /dev/null && echo "success" || echo 'failed'
""", returnStdout: true)
echo "${curl_image_exists_status_code}"
return (curl_image_exists_status_code == 'success')?true: false
}
but the output is
success
null
and the last line returns false
the output of curl_image_exists_status_code
should be success and the last line should return true but why it is not working?
try
def docker_images(image_name,image_tag){
def curl_image_exists_status_code=sh (
script:""" docker login -u XXXXX -p $$$ 2> /dev/null 1>/dev/null
docker pull XXXXX/'${image_name}':'${image_tag}' > /dev/null && echo "success" || echo 'failed'
""", returnStdout: true)
echo "${curl_image_exists_status_code}"
return (curl_image_exists_status_code == 'success')?true: false
}
You need to add .trim() to the output of your sh to be as follow:
def docker_images(image_name,image_tag){
def curl_image_exists_status_code =
curl_image_exists_status_code=sh (
script:""" docker login -u XXXXX -p $$$ 2> /dev/null 1>/dev/null
docker pull XXXXX/'${image_name}':'${image_tag}' > /dev/null && echo "success" || echo 'failed'
""", returnStdout: true).trim() //this will make your output trimmed
echo "${curl_image_exists_status_code}"
return (curl_image_exists_status_code == 'success')?true: false
}