jenkinsgroovyjenkins-pipeline

Jenkins pipeline job: Set sleep time from a string parameter?


I'm new to Jenkins Pipeline jobs, and I'm facing an issue I cannot solve.

I have a stage with a hardcoded sleep seconds value:

stage ("wait_prior_starting_smoke_testing") {
  echo 'Waiting 5 minutes for deployment to complete prior starting smoke testing'
  sleep 300 // seconds
}

But I would like to provide the time argument via a job (string) parameter SLEEP_TIME_IN_SECONDS. But whatever I have tried, I am not able to get it to work.

How do you convert a string parameter to the int time argument?


Solution

  • Finally I did found a way to get this work:

    stage ("wait_prior_starting_smoke_testing") {
        def time = params.SLEEP_TIME_IN_SECONDS
        echo "Waiting ${SLEEP_TIME_IN_SECONDS} seconds for deployment to complete prior starting smoke testing"
        sleep time.toInteger() // seconds
    }