满足条件时,对整个管道使用特殊代理 [英] Use special agent for whole pipeline when a condition is met

查看:56
本文介绍了满足条件时,对整个管道使用特殊代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有声明性管道.在管道块的开头,使用agent指令进行代理选择.正在进行基于标签的选择.通过这种方式选择的代理是标准/默认代理.

There is declarative pipeline. In the beginning of pipeline block the agent selection is made using agent directive. Label-based selection is being conducted. Agent selected this way is the standard/default agent.

在满足某些条件时如何为整个管道设置特殊代理?

How to set for whole pipeline a special agent when certain condition is met?

计划是基于管道的一个参数进行状态检查>>可以吗?

The plan is to do condition check based on pipeline's one parameter >> can that work?

所选方法需要解决的要点是什么?

What are the points the chosen approach needs to address?

当前解决方案蓝图:

  • 流水线块之前的Groovy代码

  • Groovy code prior to pipeline block

提到的Groovy代码根据管道参数的值设置一个变量如何从管道外的Groovy代码中访问管道的参数?

Mentioned groovy code sets a variable based on value of pipeline's parameter how to access pipeline's parameter from within Groovy code located out of pipeline?

agent部分使用Groovy代码匹配附加了特殊代理标签的标签中设置的变量

agent section uses variable set in Groovy code matching label special agent got attached to

推荐答案

Jenkins.io和Cloudbees都不支持使用声明性管道语法进行动态代理选择.因此,在代理程序块中添加"when"表达式将不起作用.但是,可以尝试以下方法 1.创建管道库-在vars文件夹中带有一个groovy文件.将所有阶段保留在该文件中,并参数化"Agent"块 2. Jenkinsfile-将库嵌入Jenkinsfile内,并使用call(body)语法调用上述常规文件.通过此Jenkinsfile传递代理决定参数.

Both Jenkins.io and Cloudbees do not support dynamic agent selection with Declarative Pipeline syntax. Hence adding "when" expression within agent block will not work. However, the below approach can be tried 1. Create pipeline library - with a groovy file in vars folder. Keep all the stages inside this file and parameterize the "Agent" block 2. Jenkinsfile - embed the library inside Jenkinsfile and invoke the above groovy file using call(body) syntax. Pass agent deciding parameter from this Jenkinsfile.

有关库语法,请参考此网址 共享库语法

For library syntax, please refer this url Shared Library syntax

这篇关于满足条件时,对整个管道使用特殊代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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