在 Azure DevOps 中脚本失败后继续构建

Pet*_*sma 0 azure-devops azure-pipelines

在我的 Azure DevOps 构建任务中,我运行了 Cypress 测试。如果测试失败,则取消构建。但是我想在赛普拉斯发布测试结果后运行另一个任务。

我已经在我的 pipeline.yml 文件中尝试了这个任务:

- task: PowerShell@2
  inputs:
    targetType: "inline"
    script: "yarn test:cypress"
    errorActionPreference: "continue"
  displayName: "start server and run cypress"
Run Code Online (Sandbox Code Playgroud)

但这似乎没有任何影响。

我试过添加-ErrorAction 'Continue'到脚本”

"start": "npm-run-all -s build:shared-web run:shell",
"cy:run": "cypress run -ErrorAction 'Continue'",
"test:cypress": "start-server-and-test start http://localhost:3000 cy:run"
Run Code Online (Sandbox Code Playgroud)

但这失败了:

错误:未知选项:-E

看起来赛普拉斯将ErrorAction视为赛普拉斯参数。

那么,如果任务失败,继续构建的正确方法是什么?

Sha*_*zyk 5

您可以将以下内容添加到任务中:

continueOnError: true
Run Code Online (Sandbox Code Playgroud)

现在,即使测试失败,构建也会继续运行。

如果您想在测试失败时使构建失败,但您只想运行一项任务来发布结果,则可以将其添加到发布测试任务中:

condition: always()
Run Code Online (Sandbox Code Playgroud)

现在发布任务将始终运行,即使测试失败并且构建取消/失败。