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

Jenkins Job Type Pipeline needs one more option to set environment path

      Hello Team,

      I have installed jenkins on my local windows 7. I have installed java 8. I have downloaded jenkins 2.0 from official website & completed setup by signing up as a admin user.

      I have spring boot project with jenkinsFile so I started creating job with pipeline. I have setup pipeline from SCM git/bitbucket. I have also added specific Branch in Branches to build & script path as jenkinsFile path.
      I have installed plugins like NodeJSPlugin. & configured in global tool configuration for NodeJS installation.
      I tried multiple ways to install bower package but it won't give me success. Also after bower I want to install gulp.
      This is how my job is created.

      please find below error log.

      [Pipeline] tool
      $ cmd /c "C:\Program Files (x86)\Jenkins\tools\jenkins.plugins.nodejs.tools.NodeJSInstallation\node-4.6.0\npm.cmd" install -g npm install -g npm
      C:\Program Files (x86)\Jenkins\tools\jenkins.plugins.nodejs.tools.NodeJSInstallation\node-4.6.0\npm -> C:\Program Files (x86)\Jenkins\tools\jenkins.plugins.nodejs.tools.NodeJSInstallation\node-4.6.0\node_modules\npm\bin\npm-cli.js
      C:\Program Files (x86)\Jenkins\tools\jenkins.plugins.nodejs.tools.NodeJSInstallation\node-4.6.0\npx -> C:\Program Files (x86)\Jenkins\tools\jenkins.plugins.nodejs.tools.NodeJSInstallation\node-4.6.0\node_modules\npm\bin\npx-cli.js
      + install@0.10.1
      + npm@5.3.0
      + npm@5.3.0
      updated 2 packages in 89.036s
      [Pipeline] stage
      [Pipeline] { (check tools)
      [Pipeline] sh
      [C:\Program Files (x86)\Jenkins\workspace\test-project-v0.1] Running shell script
      + node -v
      v6.10.0
      [Pipeline] sh
      [C:\Program Files (x86)\Jenkins\workspace\test-project-v0.1] Running shell script
      + npm -v
      3.10.10
      [Pipeline] sh
      [C:\Program Files (x86)\Jenkins\workspace\test-project-v0.1] Running shell script
      + bower -v
      C:/Program Files (x86)/Jenkins/workspace/test-project-v0.1@tmp/durable-4ecb94cf/script.sh: line 2: bower: command not found
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: script returned exit code 127
      Finished: FAILURE
      

      I tried multiple ways to install by trying Global npm packages to install as - npm install -g grunt-bower-cli, npm install -g bower, bower@1.8.0 grunt-cli .

      I have done some R&D for these errors. Please see the below details :-
      When choose Job Type as "Free Style Project" then we can set option Provide Node & npm bin/ folder to PATH Then we can build project successfully with bower & it is also displaying bower version.
      Refer attached snapshot where we can do settings for Free Style project.

      In other case we face issues which I mentioned above for bower. If we choose Job Type as Pipeline then we don't have any option to check or select Provide Node & npm bin/ folder to PATH.

      Refer attached snapshot where we can do settings for pipeline project.

      Can we not make available option (Provide Node & npm bin/ folder to PATH) for both the Job/Project type. If we can do that then this issues will be solved for all.

      Please if it is not possible on priority then please can we have some patch or anything that can solve my problem ?

      I have created thread on Google group also. Here is the link [Jenkins-CI Issue post Jenkins CI-CD Issue

          [JENKINS-45777] Jenkins Job Type Pipeline needs one more option to set environment path

          Nikolas Falco added a comment -

          I had a look the screenshots about job configuration you post but are cutted (no one configuration is visible).

          In the wiki page there are two pipeline example, anyway following the output of your pipeline job it's clear that you have an installation of NodeJS 6.10 in the system

          [C:\Program Files (x86)\Jenkins\workspace\test-project-v0.1] Running shell script
          + node -v
          v6.10.0
          

          and it wins in the PATH variable, looks like the bin folder of the NodeJS of the system installation (6.10.0) is before the bin folder of Jenkins NodeJS installation.

          When you execute the nom or node command it takes the system installation over the Jenkins installation and this is because you do not get grunt (because it was installed in Jenkins installation NodeJS).

          • Verify the PATH variable in a shell command with the following command
            echo %PATH%
          • Ensure you do not have the EnvInject plugin installed in Jenkins, otherwise you fall in JENKINS-26583 (as described in Known issues section of the wiki)
          • In the pipeline try use
            nodejs(nodeJSInstallationName: 'node-4.6.0', configId: null) {
                bat 'bower -v'
            }
            
          • As last chance uninstall the system NodeJS installation

          Nikolas Falco added a comment - I had a look the screenshots about job configuration you post but are cutted (no one configuration is visible). In the wiki page there are two pipeline example, anyway following the output of your pipeline job it's clear that you have an installation of NodeJS 6.10 in the system [C:\Program Files (x86)\Jenkins\workspace\test-project-v0.1] Running shell script + node -v v6.10.0 and it wins in the PATH variable, looks like the bin folder of the NodeJS of the system installation (6.10.0) is before the bin folder of Jenkins NodeJS installation. When you execute the nom or node command it takes the system installation over the Jenkins installation and this is because you do not get grunt (because it was installed in Jenkins installation NodeJS). Verify the PATH variable in a shell command with the following command echo %PATH% Ensure you do not have the EnvInject plugin installed in Jenkins, otherwise you fall in JENKINS-26583 (as described in Known issues section of the wiki) In the pipeline try use nodejs(nodeJSInstallationName: 'node-4.6.0', configId: null) { bat 'bower -v' } As last chance uninstall the system NodeJS installation

          Nikolas Falco added a comment - - edited

          As described in JENKINS-43593 you can also do the same suggested for the JDK/Maven

          env.NODEJS_HOME = "${tool node-4.6.0}"
          env.PATH="${env.NODEJS_HOME};${env.PATH}"
          echo ${env.PATH}
          bat 'node -version'
          

          This will come over envinject plugin issue or any system installation

          Nikolas Falco added a comment - - edited As described in JENKINS-43593 you can also do the same suggested for the JDK/Maven env.NODEJS_HOME = "${tool node-4.6.0}" env.PATH= "${env.NODEJS_HOME};${env.PATH}" echo ${env.PATH} bat 'node -version' This will come over envinject plugin issue or any system installation

          Thanks Nikolas.

          • Yes you are right it is taking system installation. But I have installed in jenkins also. How can we change npm/node to get the path from Jenkins Installation.
          • I checked EnvInject plugin is not installed in my Jenkins.
          • I have also attached Jenkins Global Tool Configuration setting

          • Please see the attached snapshot for complete configuration of both the style.



          Sarjerao Jadhav added a comment - Thanks Nikolas. Yes you are right it is taking system installation. But I have installed in jenkins also. How can we change npm/node to get the path from Jenkins Installation. I checked EnvInject plugin is not installed in my Jenkins. I have also attached Jenkins Global Tool Configuration setting Please see the attached snapshot for complete configuration of both the style.

          Nikolas Falco added a comment -

          How can we change npm/node to get the path from Jenkins Installation.

          In my previous post there are two way to try

          node {
             stage('build') {
                nodejs(nodeJSInstallationName: 'node-4.6.0', configId: null) {
                    bat 'bower -v'
                }
             }
          }
          
          node {
             stage('build') {
                env.NODEJS_HOME = "${tool node-4.6.0}"
                env.PATH="${env.NODEJS_HOME};${env.PATH}"
                echo ${env.PATH}
                bat 'node -version'
             }
          }
          

          Nikolas Falco added a comment - How can we change npm/node to get the path from Jenkins Installation. In my previous post there are two way to try node { stage( 'build' ) { nodejs(nodeJSInstallationName: 'node-4.6.0' , configId: null ) { bat 'bower -v' } } } node { stage( 'build' ) { env.NODEJS_HOME = "${tool node-4.6.0}" env.PATH= "${env.NODEJS_HOME};${env.PATH}" echo ${env.PATH} bat 'node -version' } }

          Sarjerao Jadhav added a comment - - edited

          Thanks I tried first way & it solved the problem. But now i am getting another issue.
          I have updated maven config in jenkins global setting. but I got this error

          [C:\Program Files (x86)\Jenkins\workspace\lease-wallet-v0.1\Lease Wallet] Running shell script
          + mvnw clean
          C:/Program Files (x86)/Jenkins/workspace/lease-wallet-v0.1/Lease Wallet@tmp/durable-7ca02bad/script.sh: line 2: mvnw: command not found
          [Pipeline] }
          [Pipeline] // dir
          [Pipeline] }
          [Pipeline] // wrap
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: script returned exit code 127
          Finished: FAILURE
          

          Please find attached snapshot for maven config. in Global setting.

          Sarjerao Jadhav added a comment - - edited Thanks I tried first way & it solved the problem. But now i am getting another issue. I have updated maven config in jenkins global setting. but I got this error [C:\Program Files (x86)\Jenkins\workspace\lease-wallet-v0.1\Lease Wallet] Running shell script + mvnw clean C:/Program Files (x86)/Jenkins/workspace/lease-wallet-v0.1/Lease Wallet@tmp/durable-7ca02bad/script.sh: line 2: mvnw: command not found [Pipeline] } [Pipeline] // dir [Pipeline] } [Pipeline] // wrap [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 127 Finished: FAILURE Please find attached snapshot for maven config. in Global setting.

          Nikolas Falco added a comment -

          Please Print your PATH variable

          Nikolas Falco added a comment - Please Print your PATH variable

          Nikolas Falco added a comment - - edited

          To have maven in your PATH do the same I posted above where instead of nodejs use

          withMaven() \{
              bat 'mvn clean install'
          }
          

          https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin

          Nikolas Falco added a comment - - edited To have maven in your PATH do the same I posted above where instead of nodejs use withMaven() \{ bat 'mvn clean install' } https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin

          Nikolas Falco added a comment -

          Update wiki documentation on how use tool to contribute the PATH variable in the same manner the JDK on Maven tool suggest for pipeline.

          Nikolas Falco added a comment - Update wiki documentation on how use tool to contribute the PATH variable in the same manner the JDK on Maven tool suggest for pipeline.

            nfalco Nikolas Falco
            sarjerav Sarjerao Jadhav
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: