Home > OS >  npm: command not found in jenkins for MAC OS
npm: command not found in jenkins for MAC OS

Time:10-17

I tried to implement CI/CD pipeline by first cloning a react project from git and then build the project in my local machine.

I have reinstalled node, configured nodejs in jenkins and tried adding PATH but nothing worked for me..

Method one that i tried: I create a freestyle item and added below script after providing the git repo link under pipeline script from SCM.. this is throwing me npm command not found error.

export PATH=/opt/homebrew
npm install

Edit:

I restarted jenkins and lost my old build..now, after restarting jenkins and running the build(above method 1 steps) i see groovy.lang.MissingPropertyException: No such property: install for class: groovy.lang.Binding

Second method i tried is by creating a new pipeline item and passing pipeline script as below.

pipeline{
agent any

tools {nodejs "default"}
stages{
    stage('Build'){
        steps{
            git '[email protected]:patebija/simple-node-js-react-npm-app.git'
            sh 'npm install'
        }
    }
}

}

Edit:

After restarting jenkins, when i run the above steps(method 2), i still see "npm: command not found"(Not sure if **sh 'npm install'** is valid in MACOS.. And if i just give **npm install** removing sh, i get exception -- groovy.lang.MissingPropertyException: No such property: install for class: groovy.lang.Binding .

I am new to jenkins and stuck with this for a long time...Appreciate any help in this regard.

Thank you

CodePudding user response:

export PATH=/opt/homebrew would override all the paths stored in $PATH, to replace it with that unique one.
That would not work very well, since all system commands would no longer be referenced.

Usually, you would add the npm path to the existing PATH

export PATH="/usr/local/bin/npm:/usr/local/bin/node:/usr/local/bin:$PATH"

(Plus possibly your existing npm packages path)

Make sure your Jenkins main controller and agents are running with your account (not as root), in order for them to inherit your environment variables.
So check first npm or git are working properly from your shell session, then launch Jenkins, and try executing pipelines.

  • Related