简体   繁体   中英

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. 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:

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'. 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.

In the job configuration, the option "Docker Container" is not enough to trigger the docker container once it triggers the physical slave.

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). In your Pipeline script you define which part is executed on which agent (slave) using the node('[AGENT_NAME]') step.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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