简体   繁体   English

如何将詹金斯管道作业链接到docker slaves容器上的标签

[英]How to link jenkins pipeline job to label on docker slaves containers

I'm looking for a way to run Jenkins jobs/build inside Jenkins slaves, dynamically (on-demand) started by docker. 我正在寻找一种通过docker动态(按需)在Jenkins奴隶内部运行Jenkins作业/构建的方法。 The scenario is the following: 该方案如下:

I have one physical slave (node name: jenkins-slave-01 and label: mySlave) which I can easily trigger jobs to it by using this code on my jenkins pipeline script: 我有一个物理从站(节点名称:jenkins-slave-01和标签:mySlave),可以通过在我的jenkins管道脚本上使用以下代码来轻松触发作业:

node ('jenkins-slave-01') {
stage ('Checkout and compile') {       
   //code ommited
}
...
//other stages ommited }

Using docker plugin , I have docker images configured as docker templates with labels 'docker-slave-01, docker-slave-02, etc'. 使用docker plugin ,我将docker镜像配置为带有docker-slave-01,docker-slave-02等标签的docker模板。 What I want is to use this images as docker slave for some pipeline jobs, but in this kind of job, the option to link this job to this label (Restrict where this project can be run and the Label expression field) is not showed. 我想要的是将这些图像用作某些管道作业的docker slave,但是在这种作业中,未显示将该作业链接到此标签的选项(限制在此项目可以运行的地方以及Label expression字段)。

In the job configuration, the option "Docker Container" is not enough to trigger the docker container once it triggers the physical slave. 在作业配置中,一旦选项“ Docker容器”触发了物理从属,则不足以触发Docker容器。

How can I handle this in a pipeline job? 如何在管道作业中处理此问题? Is it possible to do this? 是否有可能做到这一点?

A Jenkins Pipeline job always starts on a flyweight Jenkins Master executor (just after it starts you can briefly see it pop up in the Build Executor Status overview). Jenkins Pipeline作业始终在轻量级Jenkins Master执行程序上启动(刚启动后,您可以在Build Executor状态概述中短暂看到它弹出)。 In your Pipeline script you define which part is executed on which agent (slave) using the node('[AGENT_NAME]') step. 在管道脚本中,您可以使用node('[AGENT_NAME]')步骤定义在哪个代理(从属)上执行哪个部分。

Note that [AGENT_NAME] may also be a label, so if you would set up your docker agents to have the label docker-agent you can make sure your Pipeline runs on the just spawned docker agent by adding the node('docker-agent') step. 请注意, [AGENT_NAME]也可能是标签,因此,如果您将[AGENT_NAME]代理设置为具有标签docker-agent ,则可以通过添加node('docker-agent')步骤。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM