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

Environment variables cannot be set within the container step

XMLWordPrintable

    • 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."
        }
      }

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

              Created:
              Updated:
              Resolved: