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

          looks like it affects any step that sets env vars, see JENKINS-49110

          Carlos Sanchez added a comment - looks like it affects any step that sets env vars, see JENKINS-49110

          This issue may be resolved with JENKINS-42582.

          Matthew Ludlum added a comment - This issue may be resolved with JENKINS-42582 .

          Yes, all my examples are now working as expected with version 1.3.2 of the plugin. 

          Dániel Szoboszlay added a comment - Yes, all my examples are now working as expected with version 1.3.2 of the plugin. 

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

              Created:
              Updated:
              Resolved: