Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 778
Juha Jääskeläinen Avatar asked May 11 '17 10:05

Juha Jääskeläinen


People also ask

How do you pass a parameter in Jenkins pipeline script?

Using build parameters, we can pass any data we want: git branch name, secret credentials, hostnames and ports, and so on. Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.

How do you use a Boolean parameter in Jenkins pipeline?

Step 1: Click on Configure. Step 2: Then look for “This project is parameterized” checkbox. Then check the checkbox. A small section will open up for you to enter the details in.

How do I put Jenkins to sleep?

You can add sleep command (on Unix) in the test build action before test execution. As much as this works, it hangs an executor on Jenkins. This solution is definitely not platform independent and should be avoided at least when using Jenkins Pipelines.


2 Answers

small improve for this page:

You also can use sleep(time:3,unit:"SECONDS") if you are interested in specifying time unit of your sleep

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#sleep-sleep

like image 51
Sysanin Avatar answered Oct 02 '22 07:10

Sysanin


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 } 
like image 44
Juha Jääskeläinen Avatar answered Oct 02 '22 06:10

Juha Jääskeläinen