因此,我尝试在我们的构建服务器上运行 gulp,但不断出现上述错误。如果我使用我的用户帐户登录构建服务器,一切正常,因为我在我的帐户下全局安装了 gulp,但是当 Jenkins 运行我的 powershell 脚本时,它失败并出现错误:
The term 'gulp' is not recognized as the name of a cmdlet error
所以我尝试在我的脚本中进行全局安装,以便它与 Jenkins 使用的任何用户一起安装。
然后我在powershell脚本中添加了npm -g ls
,发现它是在系统用户下全局安装的:
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm > gulp@3.9.0
由于我仍然收到错误,所以我接受了 this post 的建议并在上面的目录中添加了一个路径变量,但仍然出现相同的错误。
有人知道我接下来可以尝试什么吗?我很困惑为什么它不起作用。
最佳答案
确保包含 gulp.exe
的目录包含在 $env:PATH
环境变量中。您可以使用 [Environment]::SetEnvironmentVariable()
方法更新机器范围的 PATH 变量。
让我们假设 gulp 可执行文件的路径是 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')
}
关于node.js - 术语 'gulp' 未被识别为 cmdlet 错误的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35159401/