在发布管道中配置 Grunt 任务

问题描述 投票:0回答:3

我已将 Grunt 任务添加到我的发布管道中。当 Grunt 任务运行时,我收到以下错误:

Grunt-cli is not installed globally (or is not in the path of the user the agent is running as) and it is not in the local working folder:

C:\agent\_work\r9\a\node_modules\grunt-cli\bin\grunt

知道如何纠正这个错误吗?

gruntjs azure-pipelines-release-pipeline
3个回答
0
投票

要确定 grunt-cli 是否已全局安装在您的系统上,请通过 CLI 运行以下命令:

npm list -g grunt-cli

如果报告

(empty)
,则通过运行以下命令全局安装
grunt-cli

npm install -g grunt-cli


0
投票

我们在(自托管)代理上的构建管道遇到了同样的问题......

我尝试在本地安装 grunt-cli 但也没有成功。

在脚本任务中运行命令

npm list -g
后,在yaml中:
- script: npm list -g
,我发现代理有另一个全局文件夹,它应该如下所示(取决于哪个用户运行
azure pipelines agent
服务,对我来说是(
local-system
):

C:\Windows\system32\config\systemprofile\AppData\Roaming\npm

因此,我将

grunt-task
配置为在该位置的
node_modules
中搜索 grunt-cli。在
yaml
管道计划中,它看起来像这样:

# Need to run at the first build, then set enabled to false
- task: Npm@1
  enabled: false
  inputs:
    command: 'custom'
    customCommand: 'install -g grunt-cli'

- task: Grunt@0
  displayName: Run Grunt tasks
  inputs:
    gruntFile: Gruntfile.js
    gruntCli: 'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt'

我必须在管道中运行

npm i -g grunt-cli
才能为代理全局安装 grunt-cli。

希望这会有所帮助!


0
投票

如果有人遇到这个问题,我采取的选项是在 Grunt 任务中:

  1. 将 Grunt 任务的工作目录设置为 gruntfile.js 的相对路径

  1. 将上面的相对路径添加到 grunt-cli 位置中的源代码中,并将工作目录留空。

注意,这假设您在 package.json 中将 grunt-cli 列为依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.