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

微笑、不失礼 提交于 2019-12-02 04:33:31

问题


I wanted to run a jenkins job by accepting a date field (in format YYYY-MM-DD) from user. I found a link where user can enter a string parameter:

job('example') {
    parameters {
        stringParam('myParameterName', 'my default stringParam value', 'my description')
    }
}

But in string param user can enter any thing. So how do I force user to enter a date field like a calender field and select date from the calender ?


回答1:


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!')
    }
  }
}


来源:https://stackoverflow.com/questions/35981386/how-do-i-run-a-jenkins-job-where-user-can-enter-a-date-value

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