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

Environment variables cannot be set within the container step

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • kubernetes-plugin
    • None

      Environment variables defined within a container step are not available to sh steps, only environment variables defined prior to the container step. So this scenario (for which a testcase already exists) works:

      withEnv(['foo=1']) {
        container('container') {
          sh 'echo foo=$foo' // prints foo=1
        }
      }

      But this one doesn't:

      container('container') {
        withEnv(['foo=1']) {
          sh 'echo foo=$foo' // prints foo=
        }
      }

      Nor do other things that would manipulate the environment:

      container('container') {
        env.foo = 1
        sh 'echo foo=$foo' // prints foo=
      }

      For example, this also causes problems when using sshagent, as the sh step cannot see the SSH_AUTH_SOCK environment variable:

      container('container') {
        sshagent(['credential-id']) {
          sh 'ssh-add -l' // fails with message "Could not open a connection to your authentication agent."
        }
      }

          [JENKINS-49370] Environment variables cannot be set within the container step

          Dániel Szoboszlay created issue -
          Carlos Sanchez made changes -
          Link New: This issue is related to JENKINS-49110 [ JENKINS-49110 ]
          Carlos Sanchez made changes -
          Link New: This issue is duplicated by JENKINS-49110 [ JENKINS-49110 ]
          Carlos Sanchez made changes -
          Link Original: This issue is related to JENKINS-49110 [ JENKINS-49110 ]
          Jesse Glick made changes -
          Link New: This issue is duplicated by JENKINS-42582 [ JENKINS-42582 ]
          Carlos Sanchez made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          David Schott made changes -
          Link New: This issue causes JENKINS-47210 [ JENKINS-47210 ]

            csanchez Carlos Sanchez
            dszoboszlay Dániel Szoboszlay
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: