Environment variables cannot be set within the container step

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

XMLWordPrintable

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

            Assignee:
            Carlos Sanchez
            Reporter:
            Dániel Szoboszlay
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: