gpt4 book ai didi

azure - 当我的 linting 脚本返回错误时,如何让 Azure DevOps Pipeline 构建失败?

转载 作者:行者123 更新时间:2023-12-04 22:54:45 25 4
gpt4 key购买 nike

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

这是我的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://learn.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 上失败

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec8b89838b9e8d9c84c18189acdcc2ddc2dc" rel="noreferrer noopener nofollow">[email protected]</a> 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! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6d1d3d9d1c4d7c6de9bdbd3f68698879886" rel="noreferrer noopener nofollow">[email protected]</a> lint: `eslint src`
npm ERR! Exit status 1 # Exit status 1, yet the build succeeds?
npm ERR!
npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8deae8e2eaffecfde5a0e0e8cdbda3bca3bd" rel="noreferrer noopener nofollow">[email protected]</a> 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

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a4d4f454d584b5a4207474f6a1a041b041a" rel="noreferrer noopener nofollow">[email protected]</a> slint /home/vsts/work/1/s
> stylelint src


> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="791e1c161e0b18091154141c394957485749" rel="noreferrer noopener nofollow">[email protected]</a> build /home/vsts/work/1/s
> react-scripts build

Creating an optimized production build...
Compiled successfully.

# Truncated...

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

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

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

提前谢谢您。

最佳答案

这意味着您的脚本“吞掉”退出代码并正常退出。您需要在脚本中添加一个检查,以捕获 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

关于azure - 当我的 linting 脚本返回错误时,如何让 Azure DevOps Pipeline 构建失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55194446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com