Jenkins管道作业:从字符串参数设置睡眠时间?
我是詹金斯管道工作的新手,我面临着一个我无法解决的问题 我有一个带有硬编码Jenkins管道作业:从字符串参数设置睡眠时间?,jenkins,groovy,jenkins-pipeline,Jenkins,Groovy,Jenkins Pipeline,我是詹金斯管道工作的新手,我面临着一个我无法解决的问题 我有一个带有硬编码睡眠秒值的阶段: stage ("wait_prior_starting_smoke_testing") { echo 'Waiting 5 minutes for deployment to complete prior starting smoke testing' sleep 300 // seconds } 但我想通过作业(字符串)参数SLEEP\u time\u(以秒为单位)提供时间参数。但无论我做了什
睡眠秒值的阶段:
stage ("wait_prior_starting_smoke_testing") {
echo 'Waiting 5 minutes for deployment to complete prior starting smoke testing'
sleep 300 // seconds
}
但我想通过作业(字符串)参数SLEEP\u time\u(以秒为单位)
提供时间参数。但无论我做了什么尝试,我都无法让它发挥作用
如何将字符串参数转换为int
time参数?最后,我找到了一种方法来完成这项工作:
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
}
此页面的小改进:
如果您想指定睡眠的时间单位,也可以使用睡眠(时间:3,单位:“秒”)
试试这个。这对我有用
stage ("wait_for_testing")
{
sh 'sleep 300'
}
使用“sh”可以用shell启动虚拟终端。如果您需要在一个终端中写入其他命令,请写入;在命令之后。
例如:
sh 'pwd; sleep 300; echo "Hello World"'