如何在用户可以输入日期值的情况下运行Jenkins作业? [英] How do I run a Jenkins job where user can enter a date value?

查看:157
本文介绍了如何在用户可以输入日期值的情况下运行Jenkins作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过接受用户的日期字段(格式为YYYY-MM-DD)来运行jenkins作业.我找到了一个链接,用户可以在其中输入

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 ?

推荐答案

似乎没有提供日期选择器的插件.

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

但是您可以使用验证字符串参数插件,可以使用正则表达式来验证字符串参数.请参阅用于验证日期格式dd/mm/yyyy的正则表达式与日期值匹配的正则表达式.

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.

Job DSL插件不支持验证字符串参数"插件的内置支持,但是您可以使用

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

这篇关于如何在用户可以输入日期值的情况下运行Jenkins作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆