-
New Feature
-
Resolution: Fixed
-
Minor
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
Resolution | New: Fixed [ 1 ] | |
Status | Original: Open [ 1 ] | New: Closed [ 6 ] |
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: |
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} |
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} |
Thinking about it again, that should be a Jenkins issue not kubernetes-plugin issue. Do you have any advice on how to overcome this?