Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48135

kubernetes-plugin should support multiple containers in declarative templates

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • kubernetes-plugin
    • None

      e.g. something like this

      pipeline {
        agent {
          kubernetes {
            label 'mypod'
            podTemplate {
              containerTemplate {
                name 'maven'
                image 'maven:3.3.9-jdk-8-alpine'
                ttyEnabled true
                command 'cat'
              }
              containerTemplate {
                name 'node'
                image 'node:9.2'
                ttyEnabled true
                command 'cat'
              }
            }
          }
        }
        environment {
          CONTAINER_ENV_VAR = 'container-env-var-value'
        }
        stages {
          stage('Run maven') {
            steps {
              container('maven') {
                sh 'echo INSIDE_CONTAINER_ENV_VAR = ${CONTAINER_ENV_VAR}'
                sh 'mvn -version'
              }
            }
          }
          stage('Run npm') {
            steps {
              container('node') {
                sh 'echo INSIDE_CONTAINER_ENV_VAR = ${CONTAINER_ENV_VAR}'
                sh 'npm -version'
              }
            }
          }
        }
      }
      

          [JENKINS-48135] kubernetes-plugin should support multiple containers in declarative templates

          James Strachan created issue -
          James Strachan made changes -
          Link New: This issue is blocking JENKINS-46658 [ JENKINS-46658 ]
          Carlos Sanchez made changes -
          Link New: This issue is blocked by JENKINS-48050 [ JENKINS-48050 ]

          This should be handled by JENKINS-48050

          Carlos Sanchez added a comment - This should be handled by JENKINS-48050

          I don't see how JENKINS-48050 is gonna help define podTemplates and the associated kubernetes metadata (volumes, volume mounts, serviceAccounts, secrets et al)

          James Strachan added a comment - I don't see how  JENKINS-48050  is gonna help define podTemplates and the associated kubernetes metadata (volumes, volume mounts, serviceAccounts, secrets et al)

          I had a little spike trying to implement this - so far I'm stuck on how to populate KubernetesDeclarativeAgent with a podTemplate and nested containerTemplate objects using declarative syntax; I've yet to find a sample of passing a list of objects into a setter via declarative

          James Strachan added a comment - I had a little spike trying to implement this - so far I'm stuck on how to populate KubernetesDeclarativeAgent with a podTemplate and nested containerTemplate objects using declarative syntax; I've yet to find a sample of passing a list of objects into a setter via declarative

          BTW here's an attempt at an implementation:

          https://github.com/jstrachan/kubernetes-plugin/tree/48135

          it mostly seems to be working apart from I've not yet figured out the right declarative magic to be able to specify a podTemplate with > 1 containerTemplates inside it. I managed to get 1 container specified at least https://github.com/jstrachan/kubernetes-plugin/blob/48135/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/declarativePod.groovy#L5-L17

          but haven't worked out how to declaratively specify > 1 containerTemplates yet

          James Strachan added a comment - BTW here's an attempt at an implementation: https://github.com/jstrachan/kubernetes-plugin/tree/48135 it mostly seems to be working apart from I've not yet figured out the right declarative magic to be able to specify a podTemplate with > 1 containerTemplates inside it. I managed to get 1 container specified at least https://github.com/jstrachan/kubernetes-plugin/blob/48135/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/declarativePod.groovy#L5-L17 but haven't worked out how to declaratively specify > 1 containerTemplates yet

          Jorge Arco added a comment -

          Very interested on this. If I can help, ping me

          Jorge Arco added a comment - Very interested on this. If I can help, ping me

          We are trying to move teams to using K8S build agents and using the declarative syntax instead of the scripted pipelines. What is the status of bringing podTemplate to the declarative syntax?

          Mitchell Maler added a comment - We are trying to move teams to using K8S build agents and using the declarative syntax instead of the scripted pipelines. What is the status of bringing podTemplate to the declarative syntax?
          Carlos Sanchez made changes -
          Link New: This issue depends on JENKINS-46336 [ JENKINS-46336 ]

            csanchez Carlos Sanchez
            jstrachan James Strachan
            Votes:
            6 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: