def options = [:]
// If there are any TimerTriggerCause then this build was started by a cron timer
if (currentBuild.getBuildCauses('hudson.triggers.TimerTrigger$TimerTriggerCause')) {
// Options to default to when running automatically on a schedule
options = [
FOO: 'foo default could be different for auto-scheduled runs',
BAR: true,
]
} else {
// Interactive option selection
options = input message: 'Select options',
parameters: [
string(name: 'FOO', defaultValue: 'foo default for interactive selection input', trim: true, description '...'),
booleanParam(name: 'BAR', defaultValue: true, description: '...'),
]
}
echo "Chosen: ${options.toString()}"
if (options.BAR) {
// do something based on `options.FOO`
}
1条答案
按热度按时间qeeaahzv1#
在这种情况下,我找不到一种内置的方法来让
input
返回其默认值,但是你可以手动完成,如下所示:不幸的是,您必须手动保持2个if块在添加/修改/删除参数方面“同步”,以便
options
在任何情况下都有一组一致的密钥。