当我的 linting 脚本返回错误时,如何使我的 Azure DevOps Pipeline 构建失败? [英] How do I get my Azure DevOps Pipeline build to fail when my linting script returns an error?

查看:27
本文介绍了当我的 linting 脚本返回错误时,如何使我的 Azure DevOps Pipeline 构建失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Azure Pipelines GitHub 插件来确保拉取请求通过我的 linting.但是,我刚刚提出了一个测试拉取请求,但我的 linting 失败了,但 Azure Pipeline 成功了.

I am using the Azure Pipelines GitHub add-on to ensure that pull requests pass my linting. However, I have just made a test pull request which fails my linting, but the Azure Pipeline succeeds.

这是我的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

> geograph-me@0.1.0 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! geograph-me@0.1.0 lint: `eslint src`
npm ERR! Exit status 1 # Exit status 1, yet the build succeeds?
npm ERR! 
npm ERR! Failed at the geograph-me@0.1.0 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

> geograph-me@0.1.0 slint /home/vsts/work/1/s
> stylelint src


> geograph-me@0.1.0 build /home/vsts/work/1/s
> react-scripts build

Creating an optimized production build...
Compiled successfully.

# Truncated...

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

As you can see, linter runs nicely and catches my intentional error (I removed a prop type validation), and exits with code 1.

然而,构建只是继续它的快乐方式.

However the build just carries on its merry way.

我需要做什么才能使这样的 linting 错误停止我的构建并且不返回成功?

What do I need to do to make such a linting error stop my build in its tracks and not return success?

提前致谢.

推荐答案

这意味着您的脚本吞下"了退出代码并正常退出.您需要在脚本中添加一个检查,以捕获 npm run lint 的退出代码并以相同的退出代码退出,例如:

this means your script "swallows" the exit code and exits normally. you need to add a check to your script that would catch the exit code of your npm run lint and exit with the same exit code, something like:

- 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

这篇关于当我的 linting 脚本返回错误时,如何使我的 Azure DevOps Pipeline 构建失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆