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

混江龙づ霸主 提交于 2020-01-22 10:29:07

问题


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?


回答1:


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
}



回答2:


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



来源:https://stackoverflow.com/questions/43912821/jenkins-pipeline-job-set-sleep-time-from-a-string-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!