jenkins - 如何将输入值传递给计划的 Jenkins 管道作业?
问题描述
我有一个没有任何构建参数的 Jenkins 管道。但input
里面有模板。因此,当使用 开始作业时Build now
,它会被触发并等待用户输入,Input Requested
并且将选项填充为选项。
当我手动运行时,这工作正常。但是,我想为input
选择变量启用默认值,这样当计划的作业开始时,它不会等待用户输入(通过Input Requested
)并继续使用默认值。
我的输入模板看起来像这样。
env.cluster_to_select = input(
id: 'cluster_to_select', message: 'Select a choice',
parameters: [
choice(name: 'clusters',
choices: env.list_files, //can take from populated string
description: 'Based on cluster selection, nodes are shown'
)
]
)
如何知道作业是否通过调度程序触发并传递输入的默认值。
解决方案
您可以将其包装input
在一个timeout
块中,该块本身应该在一个try
块中。然后捕获异常,检查它是否超时或被用户中止,并相应地使用默认参数或中止构建。
env.cluster_to_select = try {
timeout(time: 120, unit: 'SECONDS') {
input(
id: 'cluster_to_select', message: 'Select a choice',
parameters: [
choice(name: 'clusters',
choices: env.list_files, //can take from populated string
description: 'Based on cluster selection, nodes are shown'
)
]
)
}
} catch(err) { // timeout reached or input aborted by user
def user = err.getCauses()[0].getUser()
if (user.toString() == 'SYSTEM') { // SYSTEM is timeout
echo('Using default parameters')
} else {
currentBuild.result = 'ABORTED'
error("Pipeline aborted by: [${user}]")
}
}
推荐阅读
- python - “在 Python 控制台中运行文件”查找错误目录
- python - 在 jupyter notebook 的 python 源代码中调用函数
- powershell - 如何在 Powershell 中安装 Mailkit
- github - 当脚本在本地运行时 GitHub Actions 失败,在自托管上没有问题,因为 NPM 警告
- php - PayPal PHP SDK 1.14 致命错误,无法解决错误
- python - Python:获取裁剪区域外的平均颜色
- firebase - Flutter - Firebase:迭代列表中的子列表
- assembly - 如何将对应的 (*) 值显示为 2 位十六进制数字在四位 7 段 LED 显示屏的最右边两位?
- php - 提交按钮只保存一个输入框
- php - Magento 2 数据补丁问题