How to use podTemplate in a declarative pipeline with the kubernetes-plugin.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to use podTemplate in a declarative pipeline with the kubernetes-plugin.

Vincent Heet
Hi,

I configured a declarative pipeline with the kubernetes-plugin to start a jenkins job's in a k8s cluster. This is working great but now I want to use volumes for secrets and need to specify a podTemplate. I'm not sure how to configure a podTemplate for a declarative pipeline. The pipeline that is working:


pipeline {
    agent
{
        kubernetes
{
            label
'jenkins-demo'
            containerTemplate
{
                name
'dind-jdk8-maven3'
                image
'eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4'
                ttyEnabled
true
                command
'cat'
           
}
       
}
   
}
    stages
{
   
}
}


The above I would like to extend with a podTemplate containing volumes and a secretVolume. The issue is that I don't know the correct syntax for specifying a podTemplate in the declarative pipeline. So I came up with this:


pipeline {
    agent
{
        kubernetes
{
            label
'jenkins-demo'
            podTemplate
{
                volumes
{
                    secretVolume
(secretName: 'some-secret', mountPath: '/some-secret')
               
}
                containerTemplate
{
                    name
'dind-jdk8-maven3'
                    image
'eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4'
                    ttyEnabled
true
                    command
'cat'
               
}
           
}
       
}
   
}
    stages
{
   
}
}


Ofcourse this doesn't work an throws an error. Can anyone help me out with specifying a podTemplate so I can use k8s secrets?

Thanks,
Vincent

--
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/a69efdfc-7c1c-4e4f-a909-0b43ad95868b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use podTemplate in a declarative pipeline with the kubernetes-plugin.

Carlos Sanchez

On Thu, Aug 10, 2017 at 9:22 AM, Vincent Heet <[hidden email]> wrote:
Hi,

I configured a declarative pipeline with the kubernetes-plugin to start a jenkins job's in a k8s cluster. This is working great but now I want to use volumes for secrets and need to specify a podTemplate. I'm not sure how to configure a podTemplate for a declarative pipeline. The pipeline that is working:


pipeline {
    agent
{
        kubernetes
{
            label
'jenkins-demo'
            containerTemplate
{
                name
'dind-jdk8-maven3'
                image
'eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4'
                ttyEnabled
true
                command
'cat'
           
}
       
}
   
}
    stages
{
   
}
}


The above I would like to extend with a podTemplate containing volumes and a secretVolume. The issue is that I don't know the correct syntax for specifying a podTemplate in the declarative pipeline. So I came up with this:


pipeline {
    agent
{
        kubernetes
{
            label
'jenkins-demo'
            podTemplate
{
                volumes
{
                    secretVolume
(secretName: 'some-secret', mountPath: '/some-secret')
               
}
                containerTemplate
{
                    name
'dind-jdk8-maven3'
                    image
'eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4'
                    ttyEnabled
true
                    command
'cat'
               
}
           
}
       
}
   
}
    stages
{
   
}
}


Ofcourse this doesn't work an throws an error. Can anyone help me out with specifying a podTemplate so I can use k8s secrets?

Thanks,
Vincent

--
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/a69efdfc-7c1c-4e4f-a909-0b43ad95868b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/CALHFn6PZQNMYN3FWH9i9OkMGWrTaeR6L6oHrMe7OoQ60v1QhSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use podTemplate in a declarative pipeline with the kubernetes-plugin.

Vincent Heet
Ok so maybe i'm able to add this myself next week. I looked at the class you mentioned but would adding the PodTemplate class as a property there fix my issue? And I'm not sure why you mention volumes, volumes would then be supported from the PodTemplate if I understand this correctly?


On Thursday, August 10, 2017 at 10:27:14 AM UTC+2, Carlos Sanchez wrote:
It is not yet possible. Volumes would need to be added to the class <a href="https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgent.java" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fkubernetes-plugin%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Forg%2Fcsanchez%2Fjenkins%2Fplugins%2Fkubernetes%2Fpipeline%2FKubernetesDeclarativeAgent.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIHUs5whk_GzsZCvI9e88ZlcPLYQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fkubernetes-plugin%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Forg%2Fcsanchez%2Fjenkins%2Fplugins%2Fkubernetes%2Fpipeline%2FKubernetesDeclarativeAgent.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIHUs5whk_GzsZCvI9e88ZlcPLYQ&#39;;return true;">https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgent.java

On Thu, Aug 10, 2017 at 9:22 AM, Vincent Heet <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="puC_bZjpBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">vince...@...> wrote:
Hi,

I configured a declarative pipeline with the kubernetes-plugin to start a jenkins job's in a k8s cluster. This is working great but now I want to use volumes for secrets and need to specify a podTemplate. I'm not sure how to configure a podTemplate for a declarative pipeline. The pipeline that is working:


pipeline {
    agent
{
        kubernetes
{
            label
'jenkins-demo'
            containerTemplate
{
                name
'dind-jdk8-maven3'
                image
'<a href="http://eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4&#39;;return true;" onclick="this.href=&#39;http://eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4&#39;;return true;">eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4'
                ttyEnabled
true
                command
'cat'
           
}
       
}
   
}
    stages
{
   
}
}


The above I would like to extend with a podTemplate containing volumes and a secretVolume. The issue is that I don't know the correct syntax for specifying a podTemplate in the declarative pipeline. So I came up with this:


pipeline {
    agent
{
        kubernetes
{
            label
'jenkins-demo'
            podTemplate
{
                volumes
{
                    secretVolume
(secretName: 'some-secret', mountPath: '/some-secret')
               
}
                containerTemplate
{
                    name
'dind-jdk8-maven3'
                    image
'<a href="http://eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4&#39;;return true;" onclick="this.href=&#39;http://eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4&#39;;return true;">eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4'
                    ttyEnabled
true
                    command
'cat'
               
}
           
}
       
}
   
}
    stages
{
   
}
}


Ofcourse this doesn't work an throws an error. Can anyone help me out with specifying a podTemplate so I can use k8s secrets?

Thanks,
Vincent

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="puC_bZjpBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/a69efdfc-7c1c-4e4f-a909-0b43ad95868b%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/a69efdfc-7c1c-4e4f-a909-0b43ad95868b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/a69efdfc-7c1c-4e4f-a909-0b43ad95868b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/a69efdfc-7c1c-4e4f-a909-0b43ad95868b%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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/4fed7d43-bbbc-46ab-a718-5e7f6e5d2a99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use podTemplate in a declarative pipeline with the kubernetes-plugin.

Carlos Sanchez
I'm not familiar with declarative pipeline, but looking at what Andrew did in KubernetesDeclarativeAgent.java I assume you need to add the pod template fields that you need in there. envVars, volumes,...

On Thu, Aug 10, 2017 at 12:03 PM, Vincent Heet <[hidden email]> wrote:
Ok so maybe i'm able to add this myself next week. I looked at the class you mentioned but would adding the PodTemplate class as a property there fix my issue? And I'm not sure why you mention volumes, volumes would then be supported from the PodTemplate if I understand this correctly?


On Thursday, August 10, 2017 at 10:27:14 AM UTC+2, Carlos Sanchez wrote:

On Thu, Aug 10, 2017 at 9:22 AM, Vincent Heet <[hidden email]> wrote:
Hi,

I configured a declarative pipeline with the kubernetes-plugin to start a jenkins job's in a k8s cluster. This is working great but now I want to use volumes for secrets and need to specify a podTemplate. I'm not sure how to configure a podTemplate for a declarative pipeline. The pipeline that is working:


pipeline {
    agent
{
        kubernetes
{
            label
'jenkins-demo'
            containerTemplate
{
                name
'dind-jdk8-maven3'
                image
'eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4'
                ttyEnabled
true
                command
'cat'
           
}
       
}
   
}
    stages
{
   
}
}


The above I would like to extend with a podTemplate containing volumes and a secretVolume. The issue is that I don't know the correct syntax for specifying a podTemplate in the declarative pipeline. So I came up with this:


pipeline {
    agent
{
        kubernetes
{
            label
'jenkins-demo'
            podTemplate
{
                volumes
{
                    secretVolume
(secretName: 'some-secret', mountPath: '/some-secret')
               
}
                containerTemplate
{
                    name
'dind-jdk8-maven3'
                    image
'eu.gcr.io/jenkins-demo/dind-jdk8-maven3:v4'
                    ttyEnabled
true
                    command
'cat'
               
}
           
}
       
}
   
}
    stages
{
   
}
}


Ofcourse this doesn't work an throws an error. Can anyone help me out with specifying a podTemplate so I can use k8s secrets?

Thanks,
Vincent

--
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 jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a69efdfc-7c1c-4e4f-a909-0b43ad95868b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/4fed7d43-bbbc-46ab-a718-5e7f6e5d2a99%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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/CALHFn6MaKM1wk6diEpczpK1Vc2pDACc_AW0J3rxKJt0-u00pAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...