我使用Azure Pipelines附加组件来确保拉入请求通过我的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://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运行得很好,并捕获了我的故意错误(我删除了一个属性类型验证),然后退出并返回代码1。
然而,构建只是继续其快乐的方式。
我需要做什么才能使这样的linting错误停止我的构建,而不是返回成功?
提前谢谢你。
发布于 2019-03-16 15:31:32
这意味着您的脚本“吞下”退出代码并正常退出。您需要在脚本中添加一个检查,以捕获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发布于 2019-09-28 00:09:01
您还可以使用npm任务。缺省设置是在出现错误时使构建失败。我也遇到了同样的问题,下面的方法对我很有效:
- task: Npm@1
displayName: 'Lint'
inputs:
command: 'custom'
customCommand: 'run lint'来自tasks的文档
- task: string # reference to a task and version, e.g. "VSBuild@1"
condition: expression # see below
continueOnError: boolean # 'true' if future steps should run even if this step fails; defaults to 'false'
enabled: boolean # whether or not to run this step; defaults to 'true'
timeoutInMinutes: number # how long to wait before timing out the task发布于 2020-02-23 01:28:47
以上两种方法都不适用于我的特定场景(windows构建代理,想要运行自定义的linting脚本,不想在package.json中使用脚本)
如果您只是从节点脚本抛出错误,管道会将其视为失败的步骤。
管道yml:
- script: 'node lint-my-stuff'
displayName: 'Lint my stuff'lint-my-stuff.js
// run eslint, custom checks, whatever
if (/* conditions aren't met */)
throw new Error('Lint step failed')
console.log('Lint passed')https://stackoverflow.com/questions/55194446
复制相似问题