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

Path set by withEnv overwritten

    XMLWordPrintable

Details

    • Bug
    • Status: In Progress (View Workflow)
    • Minor
    • Resolution: Unresolved
    • nvm-wrapper-plugin
    • None
    • Jenkins ver. 2.164.2
      nvm-wrapper-plugin 0.1.7

    Description

      Hi,
      Maybe this is intended behaviour (or maybe I'm doing something wrong) but if i have this test pipeline:

      pipeline {    
          agent none    
          stages {       
            stage("nvm") {           
            agent {label 'npm'}           
                steps {            
                   withEnv(["PATH+foo=/tmp"]) {            
                      nvm('8.10.0') {                       
                         sh 'env'                   
                     }               
                 }          
             }      
          }  
        }
      }
      

      /tmp is not on PATH:
      PATH=/var/opt/jenkins-slave/.nvm/versions/node/v8.10.0/bin:/var/opt/jenkins-slave/.nvm/versions/node/v8.10.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/rh/git19/root/bin

      However if I just switch wtihEnv and nvm around:

       steps {  
             nvm('8.10.0') {   
                 withEnv(["PATH+foo=/tmp"]) {           
                     sh 'env'      
                }  
             }
      }
      

      /tmp is now on the PATH: 
      PATH=/tmp:/var/opt/jenkins-slave/.nvm/versions/node/v8.10.0/bin:/var/opt/jenkins-slave/.nvm/versions/node/v8.10.0/bin:/goss:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/rh/git19/root/bin

       Why does this matter to me? Because our Shared Library currently has...

       withJava() {  
      withMaven() {  
      withNode() {  
      //build node with maven (don't ask) but mvn not on PATH in this case
        } 
       } 
      }
      

       ... all over the place and while refactoring it by moving the order of theses statements around isn't a biggie it's not very nice to have code that only works if the statements are in a certain order.

       So tl;dr: please change the behaviour of the code not to overwrite PATH set by withEnv or advise on some other way to work around this.
       
      Content of withNode:

      def call(String nodeVersion, Closure body) {
      
          nvm(nodeVersion) {
              configFileProvider([configFile(fileId: Constants.NODEJS_SETTINGS_ID, targetLocation: '/var/opt/jenkins-slave/.npmrc')]) {
                  body()
              }
          }
      }
      

      withMaven() uses withEnv internally:

      def call(String mavenVersion, Closure body) {
      
          def maven_home = tool name: "Maven ${mavenVersion}", type: 'maven'
          buildlog.info("MAVEN_HOME: ${maven_home}")
      
          withEnv(["PATH+MAVEN=${maven_home}/bin", "MAVEN_VERSION=${mavenVersion}"]) {
              configFileProvider([configFile(fileId: Constants.MAVEN_SETTINGS_ID, targetLocation: 'settings.xml', variable: 'MAVEN_SETTINGS')]) {
                  body()
              }
      
          }
      }
      

      Attachments

        Activity

          There are no comments yet on this issue.

          People

            atoms Tomas Salazar
            alpha60 Fredrik Broman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: