In declarative pipelines, using Matrix axis to run parallel stages, doesn't play well with the `container` DSL. 
      In the example below, the `container(${CONTAINER})` is not being resolved.

      pipeline {
      agent none
          stages {
              stage('do') {
                  matrix {
                      axes {
                          axis {
                              name 'CONTAINER'
                              values 'alpha', 'beta'
                          }
                      }
                      stages {
                          stage('Init') {
                              agent {
                                  kubernetes {
                                      yaml '''
                                      apiVersion: v1
                                      kind: Pod
                                      spec: 
                                        containers: 
                                        - name:  alpha
                                          image: alpha:1.0
                                          tty: true
                                        - name: beta
                                          image: beta:2.1
                                          tty: true                   
                                      '''
                                  }
                              }
                              stages {
                                  stage('init') {
                                     // Init steps within JNLP container
                                  }
                                  stage('build') {
                                      steps {
                                          container("${CONTAINER}") {
                                              // Steps within the container, re-using the workspace.
                                              sh '...'
                                          }
                                      }
                                  }
      }}}}}}}
       

      Is there another alternative? 

       

      update:

      It seems that just by wrapping the `container` withing `script` solves this.
      Example:

       

      pipeline {
      agent none
          stages {
              stage('do') {
                  matrix {
                      axes {
                          axis {
                              name 'CONTAINER'
                              values 'alpha', 'beta'
                          }
                      }
                      stages {
                          stage('Init') {
                              agent {
                                  kubernetes {
                                      yaml '''
                                      apiVersion: v1
                                      kind: Pod
                                      spec: 
                                        containers: 
                                        - name:  alpha
                                          image: alpha:1.0
                                          tty: true
                                        - name: beta
                                          image: beta:2.1
                                          tty: true                   
                                      '''
                                  }
                              }
                              stages {
                                  stage('init') {
                                     // Init steps within JNLP container
                                  }
                                  stage('build') {
                                      steps {
                                          script {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                          }
                                      }
                                  }
      }}}}}}}
       

       

       

       

       

       

       

          [JENKINS-71581] Dynamic container based on Matrix axis

          Nikolaos created issue -
          Nikolaos made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Closed [ 6 ]
          Nikolaos made changes -
          Description Original: In declarative pipelines, using Matrix axis to run parallel stages, doesn't play well with the `container` DSL. 
          In the example below, the `container(${CONTAINER})` is not being resolved.


          {code:java}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                          }
                                      }
          }}}}}}}
           {code}

          Is there another alternative? 
          New: In declarative pipelines, using Matrix axis to run parallel stages, doesn't play well with the `container` DSL. 
          In the example below, the `container(${CONTAINER})` is not being resolved.
          {code:java}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                          }
                                      }
          }}}}}}}
           {code}
          Is there another alternative? 

           

          update:

          It seems that just by wrapping the `container` withing `script` solves this.
          Example:

           

           
          Nikolaos made changes -
          Description Original: In declarative pipelines, using Matrix axis to run parallel stages, doesn't play well with the `container` DSL. 
          In the example below, the `container(${CONTAINER})` is not being resolved.
          {code:java}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                          }
                                      }
          }}}}}}}
           {code}
          Is there another alternative? 

           

          update:

          It seems that just by wrapping the `container` withing `script` solves this.
          Example:

           

           
          New: In declarative pipelines, using Matrix axis to run parallel stages, doesn't play well with the `container` DSL. 
          In the example below, the `container(${CONTAINER})` is not being resolved.
          {code:java}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                          }
                                      }
          }}}}}}}
           {code}
          Is there another alternative? 

           

          update:

          It seems that just by wrapping the `container` withing `script` solves this.
          Example:

           
          {code:yaml}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              script {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                              }
                                          }
                                      }
          }}}}}}}
           {code}
           

           

           

           

           

           
          Nikolaos made changes -
          Description Original: In declarative pipelines, using Matrix axis to run parallel stages, doesn't play well with the `container` DSL. 
          In the example below, the `container(${CONTAINER})` is not being resolved.
          {code:java}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                          }
                                      }
          }}}}}}}
           {code}
          Is there another alternative? 

           

          update:

          It seems that just by wrapping the `container` withing `script` solves this.
          Example:

           
          {code:yaml}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              script {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                              }
                                          }
                                      }
          }}}}}}}
           {code}
           

           

           

           

           

           
          New: In declarative pipelines, using Matrix axis to run parallel stages, doesn't play well with the `container` DSL. 
          In the example below, the `container(${CONTAINER})` is not being resolved.
          {code:yaml}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                          }
                                      }
          }}}}}}}
           {code}
          Is there another alternative? 

           

          *update:*

          It seems that just by wrapping the `container` withing `script` solves this.
          Example:

           
          {code:yaml}
          pipeline {
          agent none
              stages {
                  stage('do') {
                      matrix {
                          axes {
                              axis {
                                  name 'CONTAINER'
                                  values 'alpha', 'beta'
                              }
                          }
                          stages {
                              stage('Init') {
                                  agent {
                                      kubernetes {
                                          yaml '''
                                          apiVersion: v1
                                          kind: Pod
                                          spec:
                                            containers:
                                            - name:  alpha
                                              image: alpha:1.0
                                              tty: true
                                            - name: beta
                                              image: beta:2.1
                                              tty: true                   
                                          '''
                                      }
                                  }
                                  stages {
                                      stage('init') {
                                         // Init steps within JNLP container
                                      }
                                      stage('build') {
                                          steps {
                                              script {
                                              container("${CONTAINER}") {
                                                  // Steps within the container, re-using the workspace.
                                                  sh '...'
                                              }
                                              }
                                          }
                                      }
          }}}}}}}
           {code}
           

           

           

           

           

           

            Unassigned Unassigned
            nboy Nikolaos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: