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

kubernetes-plugin should support multiple containers in declarative templates

    XMLWordPrintable

Details

    Description

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

      Attachments

        Issue Links

          Activity

            I have created a PR that allows multiple containers using the yaml syntax

            https://github.com/jenkinsci/kubernetes-plugin/pull/306

            pipeline {
              agent {
                kubernetes {
                  label 'mypod'
                  defaultContainer: 'jnlp'
                  yaml """
            apiVersion: v1
            kind: Pod
            metadata:
              labels:
                some-label: some-label-value
            spec:
              containers:
              - name: maven
                image: maven:alpine
                command:
                - cat
                tty: true
              - name: busybox
                image: busybox
                command:
                - cat
                tty: true
            """
                }
              }
              stages {
                stage('Run maven') {
                  steps {
                    container('maven') {
                      sh 'mvn -version'
                    }
                    container('busybox') {
                      sh '/bin/busybox'
                    }
                  }
                }
              }
            }
            
            csanchez Carlos Sanchez added a comment - I have created a PR that allows multiple containers using the yaml syntax https://github.com/jenkinsci/kubernetes-plugin/pull/306 pipeline { agent { kubernetes { label 'mypod' defaultContainer: 'jnlp' yaml """ apiVersion: v1 kind: Pod metadata: labels: some-label: some-label-value spec: containers: - name: maven image: maven:alpine command: - cat tty: true - name: busybox image: busybox command: - cat tty: true """ } } stages { stage( 'Run maven' ) { steps { container( 'maven' ) { sh 'mvn -version' } container( 'busybox' ) { sh '/bin/busybox' } } } } }

            Thanks Carlos, may I know in which version your fix is included.

            kamalay Lokesh Kamalay added a comment - Thanks Carlos, may I know in which version your fix is included.
            csanchez Carlos Sanchez added a comment - https://github.com/jenkinsci/kubernetes-plugin/blob/master/CHANGELOG.md

            Hello,

            I think this Issue should be re-openend until podTemplate with multiple containers is supported (as in the initial request). The YAML is a valid workaround but adds another language (yaml) to the groovy file which reduces the readability of the Jenkinsfile.

            Kind regards,

            Michael.

             

             

            mwyraz Michael michael@wyraz.de added a comment - Hello, I think this Issue should be re-openend until podTemplate with multiple containers is supported (as in the initial request). The YAML is a valid workaround but adds another language (yaml) to the groovy file which reduces the readability of the Jenkinsfile. Kind regards, Michael.    

            ideally you exclude the yaml in a separate file (ie: kube.yaml) and load it from there. In practice because we need a node to use a function like readFile.. I ended up putting the text in the pipeline. Which is bad because now we have lots of duplicates. Indeed, I don't know if completing the implementation of podTemplate is a good idea, but there is definitely something to do here.

             

            zougi Frederic Rousseau added a comment - ideally you exclude the yaml in a separate file (ie: kube.yaml) and load it from there. In practice because we need a node to use a function like readFile.. I ended up putting the text in the pipeline. Which is bad because now we have lots of duplicates. Indeed, I don't know if completing the implementation of podTemplate is a good idea, but there is definitely something to do here.  

            People

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

              Dates

                Created:
                Updated:
                Resolved: