5

So I am trying to run gulp on our build server but keep getting the error above. Everything works fine if I log into the build server with my user account as I installed gulp globally under my account however when Jenkins runs my powershell script it fails with the error:

The term 'gulp' is not recognized as the name of a cmdlet error

So I tried to install globally in my script so that it installs with whatever user Jenkins uses.

Then I added npm -g ls to The powershell script and found that it is installed globally under a system user:

C:\Windows\system32\config\systemprofile\AppData\Roaming\npm > [email protected]

Since I am still getting the error I took the advice from this post and added a path variable with the directory above however still the same error.

Anyone have ideas on what I can try next? Im stumped as to why it is not working.

3
  • Which user account is Jenkins using? Can you log into this account and try to run gulp from the command line? Commented Feb 2, 2016 at 17:02
  • it is using a system user. I cannot login with that user. Commented Feb 2, 2016 at 17:36
  • In that case, can you run Jenkins as your user account and see if it will go through? Commented Feb 2, 2016 at 17:39

2 Answers 2

1

Make sure the directory containing gulp.exe is contained in the $env:PATH environment variable. You can update the machine-wide PATH variable with the [Environment]::SetEnvironmentVariable() method.

Let's imagine the path to the gulp executable is C:\Program Files\gulp\bin\gulp.exe

# Directory containing exe
$GulpFolderPath = 'C:\program files\gulp\bin'

# Retrieve user-agnostic PATH environment variable value
$CurrentEnvPath = [Environment]::GetEnvironmentVariable('PATH','Machine')

# Check if PATH already contains gulp
if($CurrentEnvPath -split ';' -notcontains $GulpFolderPath)
{
    # if not, update it
    $NewEnvPath = $CurrentEnvPath,$GulpFolderPath -join ';'
    [Environment]::SetEnvironmentVariable('PATH',$NewEnvPath,'Machine')
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but still not working. I will try and add some Write-Host statements to see "if PATH already contains gulp" is ever entered. Aslo Since it is gulp it is not an .exe file. I am specifying the path to the .cmd file. Not sure if that is correct.
.cmd vs .exe won't make a difference
I have the same issue... did you fix this?
0

Finally a true GULP solution

After having searched for a solution the past two days without success, a colleague assisted me by running the following commands, the first installs gulp locally and globally and the second which I attribute the success for gulp finally running, installs the angular cli globally:

npm i -g gulp gulp
npm i @angular/cli -g

Afterwards I ran this command to update npm packages globally and locally; gulp finally worked:

npm install -g npm

Now running gulp -v yields success:

CLI version: 2.2.0
Local version: 4.0.2

NB: My OS is Windows 10 64 bit architecture latest updates on the 17th of July 2019. No proxy settings, no network ristrictions!!

If you do have a proxy before the internet configure your .npmrc file found by running the command npm config edit from your command line application:

proxy=x.x.x.x:PORT/
https-proxy=x.x.x.x:PORT/

prefix=C:\npm\node_modules
cache=C:\npm\cache

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.