简体   繁体   English

Jenkins - 如何在声明性管道中指定 Active Choice Reactive 参数?

[英]Jenkins - How to specify an Active Choice Reactive parameter in a declarative pipeline?

I am trying to implement a Jenkins pipeline whereby I want to control the source code for the pipeline code in git.我正在尝试实现 Jenkins 管道,借此我想控制 git 中管道代码的源代码。

To declare my parameters in a Declarative pipeline, I'll have to adhere to the following syntax:-要在声明式管道中声明我的参数,我必须遵守以下语法:-

...
pipeline {
    parameters {
        ...
    }
...
}

For the parameters section, how can I declare an Active Choice Reactive parameter, so that I can programatically populate the choices using a groovy script?对于参数部分,如何声明 Active Choice Reactive 参数,以便我可以使用 groovy 脚本以编程方式填充选项?

I know this is possible using the Jenkins UI using the Configure pipeline option, however I am trying to understand how I can implement this behavior in Groovy code.我知道使用Configure管道选项的 Jenkins UI 可以做到这一点,但是我试图了解如何在 Groovy 代码中实现此行为。

Thank you谢谢

Jenkins dynamic declarative pipeline parameters Jenkins 动态声明管道参数

Look at solution in post #5, not the accepted.查看帖子 #5 中的解决方案,而不是接受的解决方案。 It works well always.它总是运作良好。 This is the only way for now cause Active Choices (AC) built for scripted pipelines and not straightforward support declarative pipelines.这是目前唯一导致为脚本化管道构建的主动选择 (AC) 而不是直接支持声明性管道的方法。 I work a lot with AC in declarative pipelines, so my own decision is always move all the properties (parameters) wrote in scripted way before "pipeline" and even use it in Shared Libraries (as init function) or load from disc if needed and all other pipeline writing in declarative way to get all the advantages of both.我在声明性管道中使用 AC 进行了很多工作,所以我自己的决定总是在“管道”之前移动以脚本方式编写的所有属性(参数),甚至在共享库中使用它(作为 init 函数)或在需要时从磁盘加载和所有其他管道都以声明方式编写,以获得两者的所有优点。

Additional benefit of that trick that I can reuse pipeline with different parameters cause loading them on the fly from Git or Shared Libraries.该技巧的额外好处是我可以重用具有不同参数的管道,导致从 Git 或共享库动态加载它们。

Found lifehack: To built Groovy script of different codes and AC types go to pipeline syntax constructor, select "input" > "This build is parametrized" > add there needed AC > fill all the fields and choose options as needed (same as in Job UI) > Generate code.发现lifehack:要构建不同代码和AC类型go的Groovy脚本到管道语法构造函数,select根据需要选择“输入”>“此构建在所有作业字段中选择“输入” UI) > 生成代码。 After just copy "properties block" or part of AC code and put it in your Jenkinsfile before "pipeline".只需复制“属性块”或部分 AC 代码并将其放在“管道”之前的 Jenkinsfile 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有声明性 Jenkins 管道的主动选择参数 - Active choice parameter with declarative Jenkins pipeline Jenkins 声明式管道:如何从“主动选择反应引用参数的 Groovy 脚本”调用函数? - Jenkins Declarative Pipeline: How to call functions from "Active choices reactive reference parameter's Groovy script"? Jenkins声明性管道,带有扩展选择参数 - Jenkins Declarative Pipeline with extended choice parameter 如何在声明性 Jenkins 文件中的 Jenkins 多管道中设置反应选择参数 - How to set up reactive choice parameter in Jenkins multipipeline inside declarative Jenkins file Jenkins - 如何处理主动选择反应参考参数中的复选框 - Jenkins - How to handle checkbox in Active choice reactive reference parameter Jenkins - 主动选择反应参考参数 - Jenkins - Active choice reactive reference parameter jenkins 管道中的主动选择反应参考参数 - Active Choices Reactive Reference Parameter in jenkins pipeline 如何在 Jenkins 声明性管道文件中使用选择参数 integer 值作为数组 - How to use choice parameter integer value as array in Jenkins Declarative pipeline file 如何在 Jenkins 声明性管道中循环参数值 - How to loop parameter value in Jenkins Declarative pipeline 如何在 jenkins 声明式管道中使用文件参数? - How to use file parameter in jenkins declarative pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM