Pipeline generic for two Jenkins with two different agent types

15 views
Skip to first unread message

Georges Moulinier

unread,
Feb 6, 2020, 8:00:50 AM2/6/20
to Jenkins Users

Hi !

 

I want to know how can I use different agent type in my pipeline in function of the Jenkins master executing it ?

 

There are two Jenkins master target :

One is using a kubernetes cluster for providing agent containers : agent { kubernetes { ...

One is using a docker agent : agent { docker ...

 

I am looking for a solution to make a pipeline generic which can be executed on both.

The idea is not to have stage duplications on the pipeline.

 

Is it possible ?

 

Thanks.

Georges Moulinier

unread,
Feb 14, 2020, 5:59:05 AM2/14/20
to Jenkins Users
Does anyone have an idea ?

Ivan Fernandez Calvo

unread,
Feb 14, 2020, 1:58:51 PM2/14/20
to Jenkins Users
You can detect what Jenkins master is running the pipeline by checking the environment bar JENKINS_URL , agent labels accept variables, so a simple way can be use the JENKINS_URL in the labels some thing like

agent { label “${JENKINS_URL} && linux”}

If JENKINS_URL is ‘http:// intance1.example.com’ Itwill take an agent defined with the label http:// intance1.example.com and linux

Georges Moulinier

unread,
Feb 16, 2020, 5:15:43 AM2/16/20
to Jenkins Users
Thanks Ivan for your answer.

Do you think I could "hide" this syntax " kubernetes { ..." or this "docker { ..." behind a label ?

A label represent a slave declared in Jenkins. But in my case I did'nt declare slaves directly. For one of my Jenkins master I just declared a Kubernetes cluster.

Iván Fernández Calvo

unread,
Feb 16, 2020, 8:37:10 AM2/16/20
to jenkins...@googlegroups.com

> El 16 feb 2020, a las 11:15, Georges Moulinier <moulinie...@gmail.com> escribió:
>
> Do you think I could "hide" this syntax " kubernetes { ..." or this "docker { ..." behind a label ?

On both plugins you can configure templates , those templates can be triggered by labels so you still can use the agent { label ‘my-label’
} syntax
Reply all
Reply to author
Forward
0 new messages