Pipeline generic for two Jenkins with two different agent types

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Pipeline generic for two Jenkins with two different agent types

Georges Moulinier

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.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f0a1ffc7-522a-40fd-a8cf-7985f62a84d6%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Pipeline generic for two Jenkins with two different agent types

Georges Moulinier
Does anyone have an idea ?

Le jeudi 6 février 2020 14:00:50 UTC+1, Georges Moulinier a écrit :

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.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/6d6acb4e-7816-4404-b767-b12910fe3f14%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Pipeline generic for two Jenkins with two different agent types

Ivan Fernandez Calvo
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

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0e9a41ec-3f34-450a-a24b-42b5a506a9b0%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Pipeline generic for two Jenkins with two different agent types

Georges Moulinier
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.


Le vendredi 14 février 2020 19:58:51 UTC+1, Ivan Fernandez Calvo a écrit :
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:// <a href="http://intance1.example.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fintance1.example.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFXnQORCInWfk8Pa7ynEj9wlY4QVg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fintance1.example.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFXnQORCInWfk8Pa7ynEj9wlY4QVg&#39;;return true;">intance1.example.com’ Itwill take an agent defined with the label http:// <a href="http://intance1.example.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fintance1.example.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFXnQORCInWfk8Pa7ynEj9wlY4QVg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fintance1.example.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFXnQORCInWfk8Pa7ynEj9wlY4QVg&#39;;return true;">intance1.example.com and linux

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8a4c146d-2962-43b9-8af6-231cd4a58905%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Pipeline generic for two Jenkins with two different agent types

Ivan Fernandez Calvo

> El 16 feb 2020, a las 11:15, Georges Moulinier <[hidden email]> 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

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/6D070AD1-2FA2-4144-904D-81A6755B7B30%40gmail.com.