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

container() doesn't work inside environment block

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • None
    • Jenkins 2.235.5 (official docker image)
      Pipeline: Declarative 1.7.2
      Kubernetes plugin 1.27.1.1

    Description

      The following declarative pipeline does not run the desired code in the JNLP container:

      final pod = '''
      apiVersion: v1
      kind: Pod
      spec:
        containers:
          - name: busybox
            image: busybox
            command: ['/bin/sh', '-c', 'sleep infinity & wait']
      '''
      
      final block = {
        sh returnStdout: true, script: 'git --version'
      }
      
      pipeline {
        agent {
          kubernetes {
            yaml pod
            defaultContainer 'busybox'
          }
        }
      
        environment {
          one = container('jnlp', block)
          two = container('jnlp') {
            sh returnStdout: true, script: 'git --version'
          }
        }
      
        stages {
          stage('A') {
            steps {
              sh 'echo $one'
              sh 'echo $two'
            }
          }
        }
      }
      

      So the assignment of environment variable one succeeds but two fails with a message like:

      /home/jenkins/agent/workspace/_test@tmp/durable-96f999a3/script.sh: line 1: git: not found
      

      Attachments

        Activity

          tavin Tavin Cole created issue -
          vlatombe Vincent Latombe made changes -
          Field Original Value New Value
          Attachment Capture d’écran 2020-12-23 à 14.00.00.png [ 53724 ]
          vlatombe Vincent Latombe added a comment - - edited

          Looks like a declarative bug, or an unsupported syntax. Doesn't seem to be related to the kubernetes plugin.

          Attached the generated step tree view from the above pipeline, we can clearly see the second call isn't nested under container('jnlp').

          vlatombe Vincent Latombe added a comment - - edited Looks like a declarative bug, or an unsupported syntax. Doesn't seem to be related to the kubernetes plugin. Attached the generated step tree view from the above pipeline, we can clearly see the second call isn't nested under container('jnlp') .
          vlatombe Vincent Latombe made changes -
          Component/s pipeline-model-definition-plugin [ 21706 ]
          Component/s kubernetes-plugin [ 20639 ]
          Component/s pipeline [ 21692 ]

          People

            Unassigned Unassigned
            tavin Tavin Cole
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: