How do I run a Jenkins job where user can enter a date value?

安稳与你 提交于 2019-12-02 01:01:41
daspilker

There seems to be no plugin which provides a date chooser.

But you can use the Validating String Parameter Plugin, which can use a regular expression to validate a string parameter. See Regex to validate date format dd/mm/yyyy for regular expressions matching date values.

The Job DSL plugin has no built-in support for the Validating String Parameter Plugin, but you can use a Configure Block to add the relevant config XML.

job('example') {
  configure { project ->
    project / 'properties' / 'hudson.model.ParametersDefinitionProperty' / parameterDefinitions << 'hudson.plugins.validating__string__parameter.ValidatingStringParameterDefinition' {
      name('DATE')
      description('date in YYYY-MM-DD format')
      defaultValue('2016-03-01')
      regex(/\d\d\d\d-\d\d-\d\d/)
      failedValidationMessage('Enter a YYYY-MM-DD date value!')
    }
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!