I am deploying a WAR using Jenkins and I want the final pipeline stage to actually hit the endpoint and check the JSON response. If it comes up and has the right value, then it succeeds, otherwise the build should fail.
How would I do this?
I am deploying a WAR using Jenkins and I want the final pipeline stage to actually hit the endpoint and check the JSON response. If it comes up and has the right value, then it succeeds, otherwise the build should fail.
How would I do this?
pipeline {
agent any
environment{
CHECK_URL = "https://stackoverflow.com"
CMD = "curl --write-out %{http_code} --silent --output /dev/null ${CHECK_URL}"
}
stages {
stage('Stage-One') {
steps {
script{
sh "${CMD} > commandResult"
env.status = readFile('commandResult').trim()
}
}
}
stage('Stage-Two') {
steps {
script {
sh "echo ${env.status}"
if (env.status == '200') {
currentBuild.result = "SUCCESS"
}
else {
currentBuild.result = "FAILURE"
}
}
}
}
}
}
Please change the CMD as per your need and also the post section can be used to set the build status. Thanks!
Below curl is one example of printing the Jason value
curl -s 'YOUR-URL' | \
python -c "import sys, json; print json.load(sys.stdin)['VARIABLE-TOFILTER']"