In this script , want to repeat the stage if requestState id PENDING after 2 minutes every time, and should stop if its not pending.
pipeline {
agent {
label "cicd-npe-slave0"
}
options {
buildDiscarder(logRotator(numToKeepStr: '20'))
disableConcurrentBuilds()
}
parameters {
string(name: 'access_token', defaultValue: '')
string(name: 'body', defaultValue: '')
}
stages {
stage('Execute curl command') {
steps {
script {
def response = sh(script: '''curl --location 'URL' \\
--header 'Content-Type: application/json' \\
--header 'Authorization: Bearer xxx' \\
--data '{
xxxx
}' ''', returnStdout: true).trim()
println(response)
def jsonSlurper = new groovy.json.JsonSlurper()
def jsonResponse = jsonSlurper.parseText(response)
requestState = jsonResponse.response.requestState
echo "Request State = '${requestState}'"
}
}
}
}
}
I tried many things, getting below errors for the above script If I was adding sleep intervels
Caused: java.io.NotSerializableException: groovy.json.internal.LazyMap
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:274)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
Finished: FAILURE
Here is a working solution. Please adjust it as you need.