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

withEnv does not set some environment variables

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • docker-workflow-plugin
    • None
    • Jenkins 2.32.3
      BlueOcean 1.0.0-rc1

      I don't believe this is a duplicate of JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

       

      I had a `withEnv` section that looked like:

      def flowContext(cl) {
          withEnv([
              'npm_config_cache=npm-cache',
              'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
              'http_proxy=http://proxy.mycompany.com:8080',
              'https_proxy=http://proxy.mycompany.com:8080',
              'HTTP_PROXY=http://proxy.mycompany.com:8080',
              'HTTPS_PROXY=http://proxy.mycompany.com:8080',
              'PROXY_HOST=proxy.mycompany.com',
              'PROXY_PORT=8080',
              'no_proxy=.mycompany.com'
          ]) {
              credentialsContext(cl)
          }
      }
      
      def credentialsContext(cl) {
          withCredentials([
              usernamePassword(
                  credentialsId: 'service-account-user-pass',
                  passwordVariable: 'SVC_PASS',
                  usernameVariable: 'SVC_USER'
              ),
              usernamePassword(
                  credentialsId: 'github-auth-token',
                  passwordVariable: 'GITHUB_TOKEN',
                  usernameVariable: 'GITHUB_USERNAME'
              ),
              usernamePassword(
                  credentialsId: 'service-account-maven-artifactory-token',
                  passwordVariable: 'ARTIFACTORY_USER',
                  usernameVariable: 'ARTIFACTORY_TOKEN'
              ),
              usernamePassword(
                  credentialsId: 'service-account-maven-artifactory-password',
                  passwordVariable: 'ARTIFACTORY_USER',
                  usernameVariable: 'ARTIFACTORY_PASSWORD'
              ),
              string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
              string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')
      
          ]) {
              cl()
          }
      }
      

      The credentials context is another function that exports a few credentials into the environment.
      All of the credentials would be there, but not all of the environment variables.

      This would be executed within a docker container like so:

          stage('Node Build') {
              docker.image(ciNode).inside() {
                  //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                  parallel(
                      "Root Npm Install/Build": {
                          flowContext {
                              sh('env')
                              sh('npm install')
                              sh('gulp')
                          }
                      },
                      "webapp/static Install/Build": {
                          flowContext {
                              echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                              sh('cd src/main/webapp/static && npm install')
                              sh('cd src/main/webapp/static && grunt prod')
                          }
                      },
                      failFast: true
                  )
              }
          }
      
      

      The sh('env') command within the flowContext would never show the no_proxy environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.

          [JENKINS-43077] withEnv does not set some environment variables

          David Kowis created issue -
          David Kowis made changes -
          Description Original: I don't believe this is a duplicate of https://issues.jenkins-ci.org/browse/JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

           

          I had a `withEnv` section that looked like:
          {{
          def flowContext(cl) {
              withEnv([
                  'npm_config_cache=npm-cache',
                  'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
                  'http_proxy=http://www-proxy.mycompany.com:8080',
                  'https_proxy=http://www-proxy.homedepot.com:8080',
                  'HTTP_PROXY=http://www-proxy.mycompany.com:8080',
                  'HTTPS_PROXY=http://www-proxy.mycompany.com:8080',
                  'PROXY_HOST=www-proxy.mycompany.com',
                  'PROXY_PORT=8080',
                  'no_proxy=.mycompany.com'
              ]) {
                  credentialsContext(cl)
              }
          }

          def credentialsContext(cl) {
              withCredentials([
                  usernamePassword(
                      credentialsId: 'service-account-user-pass',
                      passwordVariable: 'SVC_PASS',
                      usernameVariable: 'SVC_USER'
                  ),
                  usernamePassword(
                      credentialsId: 'github-auth-token',
                      passwordVariable: 'GITHUB_TOKEN',
                      usernameVariable: 'GITHUB_USERNAME'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-token',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_TOKEN'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-password',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_PASSWORD'
                  ),
                  string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
                  string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

              ]) {
                  cl()
              }
          }

          }}

          The credentials context is another function that exports a few credentials into the environment.
          All of the credentials would be there, but not all of the environment variables.

          This would be executed within a docker container like so:

          {{
              stage('pip-ci-node Build') {
                  docker.image(ciNode).inside() {
                      //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                      parallel(
                          "Root Npm Install/Build": {
                              flowContext {
                                  sh('env')
                                  sh('npm install')
                                  sh('gulp')
                              }
                          },
                          "webapp/static Install/Build": {
                              flowContext {
                                  echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                                  sh('cd src/main/webapp/static && npm install')
                                  sh('cd src/main/webapp/static && grunt prod')
                              }
                          },
                          failFast: true
                      )
                  }
              }
          }}

           The {{sh('env')}} command within the flowContext would never show the {{no_proxy}} environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.
          New: I don't believe this is a duplicate of https://issues.jenkins-ci.org/browse/JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

           

          I had a `withEnv` section that looked like:


          {code:groovy}
          def flowContext(cl) {
              withEnv([
                  'npm_config_cache=npm-cache',
                  'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
                  'http_proxy=http://proxy.mycompany.com:8080',
                  'https_proxy=http://proxy.mycompany.com:8080',
                  'HTTP_PROXY=http://proxy.mycompany.com:8080',
                  'HTTPS_PROXY=http://proxy.mycompany.com:8080',
                  'PROXY_HOST=proxy.mycompany.com',
                  'PROXY_PORT=8080',
                  'no_proxy=.mycompany.com'
              ]) {
                  credentialsContext(cl)
              }
          }

          def credentialsContext(cl) {
              withCredentials([
                  usernamePassword(
                      credentialsId: 'service-account-user-pass',
                      passwordVariable: 'SVC_PASS',
                      usernameVariable: 'SVC_USER'
                  ),
                  usernamePassword(
                      credentialsId: 'github-auth-token',
                      passwordVariable: 'GITHUB_TOKEN',
                      usernameVariable: 'GITHUB_USERNAME'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-token',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_TOKEN'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-password',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_PASSWORD'
                  ),
                  string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
                  string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

              ]) {
                  cl()
              }
          }
          {code}

          The credentials context is another function that exports a few credentials into the environment.
           All of the credentials would be there, but not all of the environment variables.

          This would be executed within a docker container like so:

          {code:groovy}
              stage('Node Build') {
                  docker.image(ciNode).inside() {
                      //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                      parallel(
                          "Root Npm Install/Build": {
                              flowContext {
                                  sh('env')
                                  sh('npm install')
                                  sh('gulp')
                              }
                          },
                          "webapp/static Install/Build": {
                              flowContext {
                                  echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                                  sh('cd src/main/webapp/static && npm install')
                                  sh('cd src/main/webapp/static && grunt prod')
                              }
                          },
                          failFast: true
                      )
                  }
              }

          {code}


          The {{sh('env')}} command within the flowContext would never show the {{no_proxy}} environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.
          David Kowis made changes -
          Description Original: I don't believe this is a duplicate of https://issues.jenkins-ci.org/browse/JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

           

          I had a `withEnv` section that looked like:


          {code:groovy}
          def flowContext(cl) {
              withEnv([
                  'npm_config_cache=npm-cache',
                  'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
                  'http_proxy=http://proxy.mycompany.com:8080',
                  'https_proxy=http://proxy.mycompany.com:8080',
                  'HTTP_PROXY=http://proxy.mycompany.com:8080',
                  'HTTPS_PROXY=http://proxy.mycompany.com:8080',
                  'PROXY_HOST=proxy.mycompany.com',
                  'PROXY_PORT=8080',
                  'no_proxy=.mycompany.com'
              ]) {
                  credentialsContext(cl)
              }
          }

          def credentialsContext(cl) {
              withCredentials([
                  usernamePassword(
                      credentialsId: 'service-account-user-pass',
                      passwordVariable: 'SVC_PASS',
                      usernameVariable: 'SVC_USER'
                  ),
                  usernamePassword(
                      credentialsId: 'github-auth-token',
                      passwordVariable: 'GITHUB_TOKEN',
                      usernameVariable: 'GITHUB_USERNAME'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-token',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_TOKEN'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-password',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_PASSWORD'
                  ),
                  string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
                  string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

              ]) {
                  cl()
              }
          }
          {code}

          The credentials context is another function that exports a few credentials into the environment.
           All of the credentials would be there, but not all of the environment variables.

          This would be executed within a docker container like so:

          {code:groovy}
              stage('Node Build') {
                  docker.image(ciNode).inside() {
                      //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                      parallel(
                          "Root Npm Install/Build": {
                              flowContext {
                                  sh('env')
                                  sh('npm install')
                                  sh('gulp')
                              }
                          },
                          "webapp/static Install/Build": {
                              flowContext {
                                  echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                                  sh('cd src/main/webapp/static && npm install')
                                  sh('cd src/main/webapp/static && grunt prod')
                              }
                          },
                          failFast: true
                      )
                  }
              }

          {code}


          The {{sh('env')}} command within the flowContext would never show the {{no_proxy}} environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.
          New: I don't believe this is a duplicate of https://issues.jenkins-ci.org/browse/JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

           

          I had a `withEnv` section that looked like:


          {code:none}
          def flowContext(cl) {
              withEnv([
                  'npm_config_cache=npm-cache',
                  'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
                  'http_proxy=http://proxy.mycompany.com:8080',
                  'https_proxy=http://proxy.mycompany.com:8080',
                  'HTTP_PROXY=http://proxy.mycompany.com:8080',
                  'HTTPS_PROXY=http://proxy.mycompany.com:8080',
                  'PROXY_HOST=proxy.mycompany.com',
                  'PROXY_PORT=8080',
                  'no_proxy=.mycompany.com'
              ]) {
                  credentialsContext(cl)
              }
          }

          def credentialsContext(cl) {
              withCredentials([
                  usernamePassword(
                      credentialsId: 'service-account-user-pass',
                      passwordVariable: 'SVC_PASS',
                      usernameVariable: 'SVC_USER'
                  ),
                  usernamePassword(
                      credentialsId: 'github-auth-token',
                      passwordVariable: 'GITHUB_TOKEN',
                      usernameVariable: 'GITHUB_USERNAME'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-token',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_TOKEN'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-password',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_PASSWORD'
                  ),
                  string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
                  string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

              ]) {
                  cl()
              }
          }
          {code}

          The credentials context is another function that exports a few credentials into the environment.
           All of the credentials would be there, but not all of the environment variables.

          This would be executed within a docker container like so:

          {code:none}
              stage('Node Build') {
                  docker.image(ciNode).inside() {
                      //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                      parallel(
                          "Root Npm Install/Build": {
                              flowContext {
                                  sh('env')
                                  sh('npm install')
                                  sh('gulp')
                              }
                          },
                          "webapp/static Install/Build": {
                              flowContext {
                                  echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                                  sh('cd src/main/webapp/static && npm install')
                                  sh('cd src/main/webapp/static && grunt prod')
                              }
                          },
                          failFast: true
                      )
                  }
              }

          {code}


          The {{sh('env')}} command within the flowContext would never show the {{no_proxy}} environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.
          Andrew Bayer made changes -
          Component/s New: workflow-basic-steps-plugin [ 21712 ]
          Component/s Original: pipeline [ 21692 ]
          Jesse Glick made changes -
          Description Original: I don't believe this is a duplicate of https://issues.jenkins-ci.org/browse/JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

           

          I had a `withEnv` section that looked like:


          {code:none}
          def flowContext(cl) {
              withEnv([
                  'npm_config_cache=npm-cache',
                  'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
                  'http_proxy=http://proxy.mycompany.com:8080',
                  'https_proxy=http://proxy.mycompany.com:8080',
                  'HTTP_PROXY=http://proxy.mycompany.com:8080',
                  'HTTPS_PROXY=http://proxy.mycompany.com:8080',
                  'PROXY_HOST=proxy.mycompany.com',
                  'PROXY_PORT=8080',
                  'no_proxy=.mycompany.com'
              ]) {
                  credentialsContext(cl)
              }
          }

          def credentialsContext(cl) {
              withCredentials([
                  usernamePassword(
                      credentialsId: 'service-account-user-pass',
                      passwordVariable: 'SVC_PASS',
                      usernameVariable: 'SVC_USER'
                  ),
                  usernamePassword(
                      credentialsId: 'github-auth-token',
                      passwordVariable: 'GITHUB_TOKEN',
                      usernameVariable: 'GITHUB_USERNAME'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-token',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_TOKEN'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-password',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_PASSWORD'
                  ),
                  string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
                  string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

              ]) {
                  cl()
              }
          }
          {code}

          The credentials context is another function that exports a few credentials into the environment.
           All of the credentials would be there, but not all of the environment variables.

          This would be executed within a docker container like so:

          {code:none}
              stage('Node Build') {
                  docker.image(ciNode).inside() {
                      //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                      parallel(
                          "Root Npm Install/Build": {
                              flowContext {
                                  sh('env')
                                  sh('npm install')
                                  sh('gulp')
                              }
                          },
                          "webapp/static Install/Build": {
                              flowContext {
                                  echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                                  sh('cd src/main/webapp/static && npm install')
                                  sh('cd src/main/webapp/static && grunt prod')
                              }
                          },
                          failFast: true
                      )
                  }
              }

          {code}


          The {{sh('env')}} command within the flowContext would never show the {{no_proxy}} environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.
          New: I don't believe this is a duplicate of JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

           

          I had a `withEnv` section that looked like:
          {code:none}
          def flowContext(cl) {
              withEnv([
                  'npm_config_cache=npm-cache',
                  'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
                  'http_proxy=http://proxy.mycompany.com:8080',
                  'https_proxy=http://proxy.mycompany.com:8080',
                  'HTTP_PROXY=http://proxy.mycompany.com:8080',
                  'HTTPS_PROXY=http://proxy.mycompany.com:8080',
                  'PROXY_HOST=proxy.mycompany.com',
                  'PROXY_PORT=8080',
                  'no_proxy=.mycompany.com'
              ]) {
                  credentialsContext(cl)
              }
          }

          def credentialsContext(cl) {
              withCredentials([
                  usernamePassword(
                      credentialsId: 'service-account-user-pass',
                      passwordVariable: 'SVC_PASS',
                      usernameVariable: 'SVC_USER'
                  ),
                  usernamePassword(
                      credentialsId: 'github-auth-token',
                      passwordVariable: 'GITHUB_TOKEN',
                      usernameVariable: 'GITHUB_USERNAME'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-token',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_TOKEN'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-password',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_PASSWORD'
                  ),
                  string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
                  string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

              ]) {
                  cl()
              }
          }
          {code}
          The credentials context is another function that exports a few credentials into the environment.
           All of the credentials would be there, but not all of the environment variables.

          This would be executed within a docker container like so:
          {code:none}
              stage('Node Build') {
                  docker.image(ciNode).inside() {
                      //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                      parallel(
                          "Root Npm Install/Build": {
                              flowContext {
                                  sh('env')
                                  sh('npm install')
                                  sh('gulp')
                              }
                          },
                          "webapp/static Install/Build": {
                              flowContext {
                                  echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                                  sh('cd src/main/webapp/static && npm install')
                                  sh('cd src/main/webapp/static && grunt prod')
                              }
                          },
                          failFast: true
                      )
                  }
              }

          {code}
          The {{sh('env')}} command within the flowContext would never show the {{no_proxy}} environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.
          Jesse Glick made changes -
          Component/s New: docker-workflow-plugin [ 20625 ]
          Component/s Original: workflow-basic-steps-plugin [ 21712 ]
          David Navrkal made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]
          Steven made changes -
          Description Original: I don't believe this is a duplicate of JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

           

          I had a `withEnv` section that looked like:
          {code:none}
          def flowContext(cl) {
              withEnv([
                  'npm_config_cache=npm-cache',
                  'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
                  'http_proxy=http://proxy.mycompany.com:8080',
                  'https_proxy=http://proxy.mycompany.com:8080',
                  'HTTP_PROXY=http://proxy.mycompany.com:8080',
                  'HTTPS_PROXY=http://proxy.mycompany.com:8080',
                  'PROXY_HOST=proxy.mycompany.com',
                  'PROXY_PORT=8080',
                  'no_proxy=.mycompany.com'
              ]) {
                  credentialsContext(cl)
              }
          }

          def credentialsContext(cl) {
              withCredentials([
                  usernamePassword(
                      credentialsId: 'service-account-user-pass',
                      passwordVariable: 'SVC_PASS',
                      usernameVariable: 'SVC_USER'
                  ),
                  usernamePassword(
                      credentialsId: 'github-auth-token',
                      passwordVariable: 'GITHUB_TOKEN',
                      usernameVariable: 'GITHUB_USERNAME'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-token',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_TOKEN'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-password',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_PASSWORD'
                  ),
                  string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
                  string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

              ]) {
                  cl()
              }
          }
          {code}
          The credentials context is another function that exports a few credentials into the environment.
           All of the credentials would be there, but not all of the environment variables.

          This would be executed within a docker container like so:
          {code:none}
              stage('Node Build') {
                  docker.image(ciNode).inside() {
                      //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                      parallel(
                          "Root Npm Install/Build": {
                              flowContext {
                                  sh('env')
                                  sh('npm install')
                                  sh('gulp')
                              }
                          },
                          "webapp/static Install/Build": {
                              flowContext {
                                  echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                                  sh('cd src/main/webapp/static && npm install')
                                  sh('cd src/main/webapp/static && grunt prod')
                              }
                          },
                          failFast: true
                      )
                  }
              }

          {code}
          The {{sh('env')}} command within the flowContext would never show the {{no_proxy}} environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.
          New: I don't believe this is a duplicate of JENKINS-28317 but I haven't been able to figure out if I have that version of the plugin installed on my jenkins, because I'm not sure what plugin that applies to.

           

          I had a `withEnv` section that looked like:
          {code:none}
          def flowContext(cl) {
              withEnv([
                  'npm_config_cache=npm-cache',
                  'npm_config_registry=http://npm.artifactory.mycompany.com/artifactory/api/npm/npm',
                  'http_proxy=http://proxy.mycompany.com:8080',
                  'https_proxy=http://proxy.mycompany.com:8080',
                  'HTTP_PROXY=http://proxy.mycompany.com:8080',
                  'HTTPS_PROXY=http://proxy.mycompany.com:8080',
                  'PROXY_HOST=proxy.mycompany.com',
                  'PROXY_PORT=8080',
                  'no_proxy=.mycompany.com'
              ]) {
                  credentialsContext(cl)
              }
          }

          def credentialsContext(cl) {
              withCredentials([
                  usernamePassword(
                      credentialsId: 'service-account-user-pass',
                      passwordVariable: 'SVC_PASS',
                      usernameVariable: 'SVC_USER'
                  ),
                  usernamePassword(
                      credentialsId: 'github-auth-token',
                      passwordVariable: 'GITHUB_TOKEN',
                      usernameVariable: 'GITHUB_USERNAME'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-token',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_TOKEN'
                  ),
                  usernamePassword(
                      credentialsId: 'service-account-maven-artifactory-password',
                      passwordVariable: 'ARTIFACTORY_USER',
                      usernameVariable: 'ARTIFACTORY_PASSWORD'
                  ),
                  string(credentialsId: 'slack-webhook', variable: 'SLACK_WEBHOOK_URL'),
                  string(credentialsId: 'tracker-token', variable: 'TRACKER_TOKEN')

              ]) {
                  cl()
              }
          }
          {code}
          The credentials context is another function that exports a few credentials into the environment.
          All of the credentials would be there, but not all of the environment variables.

          This would be executed within a docker container like so:
          {code:none}
              stage('Node Build') {
                  docker.image(ciNode).inside() {
                      //Do the node installs in parallel, because the npm install is the slowest part, and we can use lots of cpu
                      parallel(
                          "Root Npm Install/Build": {
                              flowContext {
                                  sh('env')
                                  sh('npm install')
                                  sh('gulp')
                              }
                          },
                          "webapp/static Install/Build": {
                              flowContext {
                                  echo "Due to bug: https://issues.jenkins-ci.org/browse/JENKINS-33510"
                                  sh('cd src/main/webapp/static && npm install')
                                  sh('cd src/main/webapp/static && grunt prod')
                              }
                          },
                          failFast: true
                      )
                  }
              }

          {code}
          The {{sh('env')}} command within the flowContext would never show the {{no_proxy}} environment variable. I eventually gave up on trying to get it set in the Jenkinsfile, and instead put it in the root container image.

            Unassigned Unassigned
            beepdog David Kowis
            Votes:
            6 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: