当linting脚本返回错误时,如何使Azure DevOps Pipeline构建失败?

扎格德

我正在使用Azure Pipelines GitHub加载项来确保提取请求能够通过我的操作。但是,我刚刚发出了一个测试请求请求,但失败了,但Azure管道成功了。

这是我的 azure-pipelines.yml

# Node.js with React
# Build a Node.js project that uses React.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

pool:
  vmImage: 'Ubuntu-16.04'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '8.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run lint # Mapped to `eslint src` in package.json
    npm run slint # `stylelint src` in package.json
    npm run build
  displayName: 'npm install and build'

这是我知道失败的分支上的输出(的一部分) npm run lint

> [email protected] lint /home/vsts/work/1/s
> eslint src


/home/vsts/work/1/s/src/js/components/CountryInput.js
  26:45  error  'onSubmit' is missing in props validation  react/prop-types
  27:71  error  'onSubmit' is missing in props validation  react/prop-types

✖ 2 problems (2 errors, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] lint: `eslint src`
npm ERR! Exit status 1 # Exit status 1, yet the build succeeds?
npm ERR! 
npm ERR! Failed at the [email protected] lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vsts/.npm/_logs/2019-03-16T05_30_52_226Z-debug.log

> [email protected] slint /home/vsts/work/1/s
> stylelint src


> [email protected] build /home/vsts/work/1/s
> react-scripts build

Creating an optimized production build...
Compiled successfully.

# Truncated...

如您所见,linter运行良好,并捕获了我的故意错误(我删除了道具类型验证),并退出代码1。

然而,构建只是继续其快乐的方式。

我要怎么做才能使这种掉毛错误使我的构建停滞不前而不返回成功?

先感谢您。

4c74356b41

这意味着您的脚本会“吞噬”退出代码并正常退出。您需要在脚本中添加一个检查,以捕获您的退出代码,npm run lint并使用相同的退出代码退出,例如:

- script: |
    npm install
    npm run lint # Mapped to `eslint src` in package.json
    if [ $? -ne 0 ]; then
        exit 1
    fi
    npm run slint # `stylelint src` in package.json
    npm run build

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Azure DevOps Pipeline构建意外触发

Azure Devops 管道 Jekyll 构建失败

Docker构建在Azure DevOps上失败

Azure DevOps Pipeline - 在管道中读取构建标记?

Azure Devops Pipeline构建资源管理器

Azure DevOps Pipeline 变量定义在构建前自动更改

Azure DevOps Pipeline dotnet ef 迁移因本地工件而失败

在 Azure DevOps Pipeline 中成功运行失败的测试

linux VM上的Azure DevOps Pipeline PostSharp失败

.net core 3.1 Azure devops Pipeline在nuget还原时失败

Azure Devops maven 构建在声纳 qube 实例中失败

Azure DevOps构建管道且托管代理失败

查询构建因超时而失败-Azure DevOps Server

使用Azure DevOps构建电子应用程序失败

从Subversion构建Azure DevOps

Spring的Azure Pipeline Gradle构建失败

Azure DevOps,如何使“ArtifactoryDotnetCore”失败

在Azure DevOps中,如何防止失败的单元测试导致构建失败?

所有测试通过时,Azure DevOps Build Pipeline中的Chutzpah Jasmine测试返回失败

Azure devops中的角度项目CI给出错误“发布构建工件失败,并显示错误:”

Azure DevOps构建管道-失败的构建仍将部署到Azure

Azure DevOps Pipeline构建代理:如何在程序集引用HintPath中使用或替换$(DevEnvDir)?

Azure devops react 本机 ios 构建失败,出现一般错误 65

Azure DevOps 管道中的 NG 构建失败:错误:找不到模块“../internal/operators/audit”

如何有条件地使 Azure Devops Pipeline 阶段失败?

预构建的 Azure Devops 板

Azure DevOps构建子模块

带参数的 Azure DevOps 构建

Azure Devops Docker Compose 构建