【问题标题】:Jenkins choice parameter with different display不同显示的Jenkins选择参数
【发布时间】:2017-01-17 07:48:32
【问题描述】:

我想向 Jenkins 作业添加选择参数。该列表是固定的,但我希望 Dropbox 显示自定义值,而不是实际值(类似于网页名称而不是其 URL)。

在某些情况下,这是pom.xml 文件的路径,但是,我想显示模块名称而不是完整路径。一个例子:

Actual value                         | What I want to be displayed
-------------------------------------|----------------------------
full/path/to/my/modules/pom.xml      | All modules
full/path/to/my/modules/util/pom.xml | Utilities
full/path/to/my/modules/data/pom.xml | Data handling

提前感谢您的帮助!

【问题讨论】:

    标签: maven jenkins pom.xml


    【解决方案1】:

    您可以使用Extended Choice Parameter plugin 来做到这一点。

    要按照你想要的方式设置它,在“This build is parameterized”下,选择 Extended Choice Parameter,然后像这样设置它:

    请注意,根据您拥有的 Jenkins 版本,它可能看起来会有些不同,但应该不会有太大不同(此屏幕截图是 2.0-beta-2 上的)。

    【讨论】:

    • 感谢您的建议!我们有这个插件的过时版本,似乎还没有这个功能。确实,Jenkins 本身有点过时,并且警告说最新版本的扩展选择插件可能不适用于我们的 Jenkins。
    【解决方案2】:

    痛苦了这么多年一直没有简单的方法解决这个问题,比如用选择插件写一个显示|值行,所以我终于写了自己的插件:https://github.com/Avalancs/ChoiceWithDisplay 您可以从发布选项卡获取 .hpi 文件,如果您不知道如何安装 .hpi 文件,请查看此 SO 帖子:https://stackoverflow.com/a/19588907/7216760

    【讨论】:

      【解决方案3】:

      使用 Active Choices 插件,您可以使用 groovy 地图进行设置:

      使用以下 groovy 脚本设置“主动选择参数”:

      return['full/path/to/my/modules/pom.xml' : 'All modules',
      'full/path/to/my/modules/util/pom.xml' : 'Utilities',
      'full/path/to/my/modules/data/pom.xml' : 'Data handling']
      

      地图的“值”将显示在构建参数选项中:

      并且地图的“key”会在变量中设置:

      > echo "$URL"
      full/path/to/my/modules/pom.xml
      

      【讨论】:

      • 我们如何只为一个参数做到这一点?
      • 它适用于列表中的单个元素:return['full/path/to/my/modules/pom.xml' : 'All modules']
      • 我收到了 groovy 错误,因为我不希望更改其他参数的显示名称。我想要这样的东西 return['full/path/to/my/modules/pom.xml' : 'All modules', 'full/path/to/my/modules/util/pom.xml' , 'full/path /to/my/modules/data/pom.xml']
      • return['full/path/to/my/modules/pom.xml' : '所有模块', 'full/path/to/my/modules/util/pom.xml' : ' full/path/to/my/modules/util/pom.xml', 'full/path/to/my/modules/data/pom.xml' : 'full/path/to/my/modules/data/pom. xml'] 应该可以工作。
      • 我知道这样,但会很长。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-08
      • 1970-01-01
      • 2017-06-04
      • 1970-01-01
      相关资源
      最近更新 更多