-
Type:
New Feature
-
Resolution: Fixed
-
Priority:
Minor
-
Component/s: kubernetes-plugin
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 '...'
                  }
}
                }
              }
}}}}}}}
Â
Â
Â
Â
Â
Â