【问题标题】:How do you get a grunt error to return on a VSTS hosted build agent您如何在 VSTS 托管的构建代理上返回 grunt 错误
【发布时间】:2018-09-11 17:59:28
【问题描述】:

我正在尝试通过批处理脚本运行 grunt 任务,并按如下方式调用 grunt:

call npm install
call npm install grunt

但是,如果这返回错误,则托管构建代理上的 VSTS 构建仍会显示为成功(即使脚本中记录了错误)。有没有人有任何很好的例子来说明如何让它向构建返回错误?

我一直在研究使用powershell,但到目前为止没有任何运气,代码如下:

在 gruntfile.js 中:

grunt.initConfig({
    shell: {
        ps: {
            options: {
                stdout: true
            },
            command: 'powershell ../../errors.ps1'
        }
    }
});

grunt.registerTask('default',  function() {
    try {
                    grunt.task.run([
                    'less:desktop',
                    'less:tablet',
                    'less:smartphone',
                    'less:homepage_desktop',
                    'less:homepage_tablet']);
    } catch(e) {
                    grunt.task.run([
                    'shell:ps']);
                    throw e;

    }
}); 

在errors.ps1中:

$URL_Format_Error = [string]"Error found in running grunt. Please investigate grunt logs"
    Write-Error $URL_Format_Error -ErrorAction:Stop
    return

在异常处理程序中运行的代码永远不会被调用,并且会在 .less 文件中输出带有编译错误的警告,但永远不会运行 powershell。有没有办法我可以挂接到警告中,然后运行我的 powershell?

作为替代方案,当我尝试在运行 NPM 安装的批处理脚本之后将 grunt 任务添加到 VSTS 构建定义时,我只是不断收到以下错误(即使在批处理脚本中看到成功的 NPM 安装之后) :

致命错误:无法找到本地咕噜声

因此,如果我使用托管构建代理,我不确定是否可以在 VSTS 构建定义的单独任务中运行 grunt 任务。我倾向于认为这只有在我拥有自己的构建服务器时才有效。

【问题讨论】:

    标签: powershell gruntjs azure-devops azure-pipelines


    【解决方案1】:

    尝试在您的脚本中将Write-Errorexit 1 结合使用。

     Write-Error ("Some error")
     exit 1
    

    参考这个帖子:How to fail the build from a PowerShell task in TFS 2015

    【讨论】:

      猜你喜欢
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多