container() doesn't work inside environment block

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      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
      

            Assignee:
            Unassigned
            Reporter:
            Tavin Cole
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: