Jenkins管道,下游作业和代理标签 [英] Jenkins Pipeline, downstream job and Agent label

查看:216
本文介绍了Jenkins管道,下游作业和代理标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行Job A和Job B的Jenkins管道.我有10个执行Job A的代理程序/节点. 如果我指定Agent1,则在构建管道时,作业A应该在Agent1上执行.

I have a Jenkins Pipeline that executes Job A and Job B. I have 10 agents/nodes on which Job A is executed. If I specify Agent1, when I Build Pipeline, then Job A should execute on Agent1.

问题: 管道正在Agent1上运行,JobA正在任何随机可用的代理上获取.

Issue: Pipeline is running on Agent1 and JobA is getting picked up on any random available agent.

脚本:

pipeline { agent none stages { stage('JOB A') { agent { label "${machine}" } steps { build job: 'JOB A', parameters: [a,b,c,d,e,f] } } stage('JOB B') { agent { label 'xyz' } steps { build job: 'JOB B', parameters: [a,b,c,d,e,f,] } } } }

pipeline { agent none stages { stage('JOB A') { agent { label "${machine}" } steps { build job: 'JOB A', parameters: [a,b,c,d,e,f] } } stage('JOB B') { agent { label 'xyz' } steps { build job: 'JOB B', parameters: [a,b,c,d,e,f,] } } } }

我为每个座席使用不同的标签.

I'm using different label for every agent.

有人可以帮助我了解管道作业和下游作业的运行方式和位置吗?

Can someone help me understand how and where the Pipeline and downstream jobs are running?

谢谢!

推荐答案

正如@yong正确指出的那样,我为阶段指定了代理标签,而不是为作业A指定了标签."

As rightly pointed by @yong, I 'specified agent label for stage, not for the JOB A'.

因此,我在作业A中声明了一个标签参数,并通过管道将其传递给下游.现在,它可以在指定的代理上正确执行.

So I declared a label parameter in JOB A and passed it downstream via the Pipeline. It's now correctly executing on the specified Agent.

pipeline {
agent { label 'master' }
stages {
    stage('JOB A') {
        steps {
            build job: 'JOB A', parameters: [a, [$class: 'LabelParameterValue', name: 'Agent', label: "${Agent}" ], b, c, d]
        }
        }
    stage('JOB B') {
        steps {
            build job: 'JOB B', parameters: [x,y,z]
        }
        }
    }
}

这篇关于Jenkins管道,下游作业和代理标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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