jenkins - 如何检查执行程序是否在 Jenkins 中运行
问题描述
如果执行程序已经在运行作业,有没有办法检查 Jenkins 管道?
我想根据这种情况使用不同的环境变量。
我想要的管道的伪代码如下
如果
触发了 Job-A 的构建
THEN
Use Environment_Variable_1
USE Executor-1 for Job-A
ELSE IF
JOB-A 在 Executor-1 上运行并且再次触发了 JOB-A 的构建
THEN
Use Environment_Variable_2
USE Executor-2 for Job-A
环境变量将保存不同文件夹的路径,因为作业将对文件夹进行更改。因此,当在执行程序 2 上再次触发作业时,我希望它更改另一个文件夹。
解决方案
如果执行程序已经在运行作业,有没有办法检查 Jenkins 管道?
是的。有了jenkins.model.Jenkins.instance.nodes
您可以获得所有已配置的节点。从这些节点中,您可以Computer
使用node.toComputer()
. 从Computer
对象可以检索Executors
该计算机上的所有内容。
for (node in jenkins.model.Jenkins.instance.nodes) {
def computer = node.toComputer() /* computer behind the node */
def executors = computer.getExecutors()
for (executor in executors) {
println("Node name: " + node.getDisplayName())
println("Computer name: " + computer.getDisplayName())
println("Executor name: " + executor.getDisplayName())
println("Executor number: " + executor.getNumber())
println("Is executor busy: " + executor.isBusy())
}
}
推荐阅读
- c++ - 在 C++ 中迭代枚举类的常用方法是什么?
- sql - 将 SQL 查询从 with 子句转移到没有 with 子句
- grails - grails如何检查双负零
- node.js - 是否有一个选项可以向我显示特定 npm 包的哪些语义版本将解析为?
- javascript - 为什么我的 React 组件将我的 JSX 渲染为文本而不是 HTML?
- javascript - ++Argument 在调用递归函数时返回的结果与参数 + 1 不同
- python - 数据帧 UDF 以获得更快的性能?
- python - 如何根据序列中的下一个值删除行?(熊猫)
- node.js - ea-nodejs10安装v10.24.1时如何在VPS cPanel WHM上安装node.js v16?
- python - KeyError:尝试按索引访问数据框列的值时,python数据框中的8