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

Set NODE_HOME variable when the nodejs tool is used

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • nodejs-plugin
    • None
    • Jenkins LTS: 2.303.1
      NodeJS Plugin: 1.4.0
    • 1.5.0

      When the nodejs tool is installed by using the tools block then:

      • the NODEJS_HOME environment variable is set
      • the PATH environment variable is expanded (inject path to the Node.js directory which keeps binaries)

      Unfortunately, the NODEJS_HOME environment variable is not a standard. Many people use the NODE_HOME environment variable instead (see Node.js installation configuration on w3big.com). We could add some workarounds like

      pipeline {
          agent any
          stages {
              stage('Build') {
                  steps {
                      nodejs(nodeJSInstallationName: 'Node 6.x', configId: '<config-file-provider-id>') {
                          withEnv(["NODE_HOME=${env.NODEJS_HOME}"]) {
                            sh 'buildScriptDevelopedByOtherPeople.sh'
                          }
                      }
                  }
              }
          }
      }
      

      but they are very messy. It would be great if both variables could be set. We need some changes in the NodeJSInstallation (extend) and NodeJSConstants (add new constant) classes. There is no need to add the PATH+NODE_HOME environment variable because the PATH+NODEJS_HOME environment variable handles the injection to the PATH environment variable correctly.

          [JENKINS-66720] Set NODE_HOME variable when the nodejs tool is used

          Adam Gabryś created issue -
          Adam Gabryś made changes -
          Summary Original: Set NODE_HOME variable when tool is used New: Set NODE_HOME variable when the nodejs tool is used
          Adam Gabryś made changes -
          Description Original: When the Node.js tool is installed by using the [tools|https://www.jenkins.io/doc/book/pipeline/syntax/#tools] block then:
          * the {{NODEJS_HOME}} environment variable is set
          * he {{PATH}} variable is expanded (inject path to the Node.js directory which keeps binaries)

          Unfortunately, the {{NODEJS_HOME}} environment variable is not a standard. Many people use the {{NODE_HOME}} environment variable instead ([see |http://www.w3big.com/nodejs/nodejs-install-setup.html]). We could add some workarounds like
          {code}
          pipeline {
              agent any
              stages {
                  stage('Build') {
                      steps {
                          nodejs(nodeJSInstallationName: 'Node 6.x', configId: '<config-file-provider-id>') {
                              withEnv(["NODE_HOME=${env.NODEJS_HOME}"]) {
                                sh 'buildScriptDevelopedByOtherPeople.sh'
                              }
                          }
                      }
                  }
              }
          }
          {code}
          but they are very messy. It would be great if both variables could be set. We need some changes in the [NodeJSInstallation|https://github.com/jenkinsci/nodejs-plugin/blob/bbd0e42fdd3d5d5e96e29cdaaba7e9858ca05f69/src/main/java/jenkins/plugins/nodejs/tools/NodeJSInstallation.java#L103-L110] (extend) and [NodeJSConstants|https://github.com/jenkinsci/nodejs-plugin/blob/bbd0e42fdd3d5d5e96e29cdaaba7e9858ca05f69/src/main/java/jenkins/plugins/nodejs/NodeJSConstants.java#L42-L51] (add new constant) classes.
          New: When the {{nodejs}} tool is installed by using the [tools|https://www.jenkins.io/doc/book/pipeline/syntax/#tools] block then:
           * the {{NODEJS_HOME}} environment variable is set
           * the {{PATH}} environment variable is expanded (inject path to the Node.js directory which keeps binaries)

          Unfortunately, the {{NODEJS_HOME}} environment variable is not a standard. Many people use the {{NODE_HOME}} environment variable instead ([see Node.js installation configuration on w3big.com|http://www.w3big.com/nodejs/nodejs-install-setup.html]). We could add some workarounds like
          {code:java}
          pipeline {
              agent any
              stages {
                  stage('Build') {
                      steps {
                          nodejs(nodeJSInstallationName: 'Node 6.x', configId: '<config-file-provider-id>') {
                              withEnv(["NODE_HOME=${env.NODEJS_HOME}"]) {
                                sh 'buildScriptDevelopedByOtherPeople.sh'
                              }
                          }
                      }
                  }
              }
          }
          {code}
          but they are very messy. It would be great if both variables could be set. We need some changes in the [NodeJSInstallation|https://github.com/jenkinsci/nodejs-plugin/blob/bbd0e42fdd3d5d5e96e29cdaaba7e9858ca05f69/src/main/java/jenkins/plugins/nodejs/tools/NodeJSInstallation.java#L103-L110] (extend) and [NodeJSConstants|https://github.com/jenkinsci/nodejs-plugin/blob/bbd0e42fdd3d5d5e96e29cdaaba7e9858ca05f69/src/main/java/jenkins/plugins/nodejs/NodeJSConstants.java#L42-L51] (add new constant) classes.
          Adam Gabryś made changes -
          Description Original: When the {{nodejs}} tool is installed by using the [tools|https://www.jenkins.io/doc/book/pipeline/syntax/#tools] block then:
           * the {{NODEJS_HOME}} environment variable is set
           * the {{PATH}} environment variable is expanded (inject path to the Node.js directory which keeps binaries)

          Unfortunately, the {{NODEJS_HOME}} environment variable is not a standard. Many people use the {{NODE_HOME}} environment variable instead ([see Node.js installation configuration on w3big.com|http://www.w3big.com/nodejs/nodejs-install-setup.html]). We could add some workarounds like
          {code:java}
          pipeline {
              agent any
              stages {
                  stage('Build') {
                      steps {
                          nodejs(nodeJSInstallationName: 'Node 6.x', configId: '<config-file-provider-id>') {
                              withEnv(["NODE_HOME=${env.NODEJS_HOME}"]) {
                                sh 'buildScriptDevelopedByOtherPeople.sh'
                              }
                          }
                      }
                  }
              }
          }
          {code}
          but they are very messy. It would be great if both variables could be set. We need some changes in the [NodeJSInstallation|https://github.com/jenkinsci/nodejs-plugin/blob/bbd0e42fdd3d5d5e96e29cdaaba7e9858ca05f69/src/main/java/jenkins/plugins/nodejs/tools/NodeJSInstallation.java#L103-L110] (extend) and [NodeJSConstants|https://github.com/jenkinsci/nodejs-plugin/blob/bbd0e42fdd3d5d5e96e29cdaaba7e9858ca05f69/src/main/java/jenkins/plugins/nodejs/NodeJSConstants.java#L42-L51] (add new constant) classes.
          New: When the {{nodejs}} tool is installed by using the [tools|https://www.jenkins.io/doc/book/pipeline/syntax/#tools] block then:
           * the {{NODEJS_HOME}} environment variable is set
           * the {{PATH}} environment variable is expanded (inject path to the Node.js directory which keeps binaries)

          Unfortunately, the {{NODEJS_HOME}} environment variable is not a standard. Many people use the {{NODE_HOME}} environment variable instead ([see Node.js installation configuration on w3big.com|http://www.w3big.com/nodejs/nodejs-install-setup.html]). We could add some workarounds like
          {code:java}
          pipeline {
              agent any
              stages {
                  stage('Build') {
                      steps {
                          nodejs(nodeJSInstallationName: 'Node 6.x', configId: '<config-file-provider-id>') {
                              withEnv(["NODE_HOME=${env.NODEJS_HOME}"]) {
                                sh 'buildScriptDevelopedByOtherPeople.sh'
                              }
                          }
                      }
                  }
              }
          }
          {code}
          but they are very messy. It would be great if both variables could be set. We need some changes in the [NodeJSInstallation|https://github.com/jenkinsci/nodejs-plugin/blob/bbd0e42fdd3d5d5e96e29cdaaba7e9858ca05f69/src/main/java/jenkins/plugins/nodejs/tools/NodeJSInstallation.java#L103-L110] (extend) and [NodeJSConstants|https://github.com/jenkinsci/nodejs-plugin/blob/bbd0e42fdd3d5d5e96e29cdaaba7e9858ca05f69/src/main/java/jenkins/plugins/nodejs/NodeJSConstants.java#L42-L51] (add new constant) classes. There is no need to add the {{PATH+NODE_HOME}} environment variable because the {{PATH+NODEJS_HOME}} environment variable handles the injection to the {{PATH}} environment variable correctly.

          Nikolas Falco added a comment - - edited

          That documentation is a bit ancient they use nodes 0.x -> 4.x

          Is the reference to NODE_HOME in some your scripts?

           

          A google search "NODE_HOME" produce two big matches... this Jenkins issue and the link you post in the description so I think this feature is very limited to you single case andthe workaround is very simple as you already post in the issue
          withEnv(["NODE_HOME=${env.NODEJS_HOME}"])

          { ... }

          Nikolas Falco added a comment - - edited That documentation is a bit ancient they use nodes 0.x -> 4.x Is the reference to NODE_HOME in some your scripts?   A google search "NODE_HOME" produce two big matches... this Jenkins issue and the link you post in the description so I think this feature is very limited to you single case andthe workaround is very simple as you already post in the issue withEnv( ["NODE_HOME=${env.NODEJS_HOME}"] ) { ... }
          Nikolas Falco made changes -
          Priority Original: Major [ 3 ] New: Minor [ 4 ]

          Adam Gabryś added a comment -

          Is the reference to NODE_HOME in some your scripts?

          I develop CI for other teams. They reported that the NODE_HOME environment variable is missing. I don't know why they use NODE_HOME instead of NODEJS_HOME. However, based on the Google search the NODE_HOME environment variable is more popular:

          I don't want to add workarounds because later the code base is horrible to maintain.

          If you think supporting both values has no sense, please close the ticket, so my customers are aware that it won't be supported.

          Adam Gabryś added a comment - Is the reference to NODE_HOME in some your scripts? I develop CI for other teams. They reported that the NODE_HOME environment variable is missing. I don't know why they use NODE_HOME instead of NODEJS_HOME . However, based on the Google search the NODE_HOME environment variable is more popular: https://www.google.com/search?q=%22NODE_HOME%22 (About 31.600 results) https://www.google.com/search?q=%22NODEJS_HOME%22 (About 1.950 results) I don't want to add workarounds because later the code base is horrible to maintain. If you think supporting both values has no sense, please close the ticket, so my customers are aware that it won't be supported.
          Nikolas Falco made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Nikolas Falco made changes -
          Released As New: 1.5.0
          Resolution New: Fixed [ 1 ]
          Status Original: In Progress [ 3 ] New: Resolved [ 5 ]

            nfalco Nikolas Falco
            agabrys Adam Gabryś
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: