jenkins - 具有相关参数的参数化 Jenkins 作业

标签 jenkins

我正在尝试创建一个具有相关参数的 Jenkins 作业。

首先,我希望能够选择一个主要参数:enter image description here
其次,能够从作为主要参数的依赖参数的一组选项中进行选择。 enter image description here

如果我选择不同的主要参数:enter image description here

然后我希望有一组不同的选项作为第二个主要参数的依赖项。 enter image description here

拜托,你能帮我解决这个问题吗?

最佳答案

我建议使用 Active Choices plugin (也称为“uno-choice”)。 ( This questionreferencesboth ,尽管它们不是公认的答案。)

对于您的特定用例,您需要向作业添加两个参数:

  • 主动选择参数
  • 姓名 : MainOption
  • 脚本 : Groovy 脚本
    return ['A','B']
    
  • 主动选择 react 参数
  • 姓名 : DependentOption
  • 脚本 :Groovy 脚本
    def choices
    switch(MainOption){
        case 'A':
            choices = ['Blue','Green','Yellow']
            break
        case 'B':
            choices = ['Black','White','Grey']
            break
        default:
            choices = ['N/A']
            break
    }
    return choices
    
  • 回退脚本 : Groovy 脚本
    return ['Option error']
    
  • 引用参数 :
    MainOption
    

  • “引用参数”设置是关键——当该值改变时,插件将重新评估 Groovy 脚本,为您提供依赖参数效果。

    关于jenkins - 具有相关参数的参数化 Jenkins 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51845050/

    相关文章:

    java - 在每个构建上从 Jenkins email-ext 向提交者发送电子邮件

    jenkins - 为什么 faSTLane 扫描测试会在 Jenkins Pipeline 中不断重建和运行?

    git - 无法解析 docker 中的主机

    jenkins - 没有为分支计划构建

    java - 配置 Jenkins 使用 Chrome - Selenium 3.0.1 Maven TestNG

    docker - Jenkins Docker 声明式 .withRun

    java - 从 Jenkins 在控制台启动 Tomcat

    regex - Jenkins Gerrit 在除 master 之外的所有分支上触发

    git - 为 Github 私有(private)存储库验证 Jenkins CI

    maven - 我的 Artifact 似乎很大,可以由 Maven 部署。我能做什么?