如何在覆盖率失败时使 Azure DevOps 管道失败?

huangapple go评论85阅读模式
英文:

How to fail an azur devOps pipeline on coverage fail?

问题

我正在使用Microsoft DevOps Forge构建我的流水线。如果覆盖率低于80%,我想让测试流水线失败,但我在Microsoft文档中找不到相关信息。

这是我的test.yaml文件:

  1. trigger:
  2. branches:
  3. include:
  4. - main
  5. pool:
  6. vmImage: windows-latest
  7. steps:
  8. - task: UsePythonVersion@0
  9. inputs:
  10. versionSpec: "3.10"
  11. displayName: "使用Python 3.10"
  12. - script: python -m pip install toto pytest pytest-cov pytest-deadfixtures
  13. displayName: "安装依赖项"
  14. - script: pytest --color=yes --cov --cov-report=html
  15. displayName: "使用pytest进行测试"
英文:

I'm building my pipelines in the Microsoft dev Ops forge. I would like to make the test pipeline to fail if the coverage is < 80% but I don't find the information in the microsoft documentation.

Here is my test.yaml file:

  1. trigger:
  2. branches:
  3. include:
  4. - main
  5. pool:
  6. vmImage: windows-latest
  7. steps:
  8. - task: UsePythonVersion@0
  9. inputs:
  10. versionSpec: &quot;3.10&quot;
  11. displayName: &quot;Use Python 3.10&quot;
  12. - script: python -m pip install toto pytest pytest-cov pytest-deadfixtures
  13. displayName: &quot;Install dependencies&quot;
  14. - script: pytest --color=yes --cov --cov-report=html
  15. displayName: &quot;Test with pytest&quot;

答案1

得分: 0

你应该切换到term输出:

  1. - bash: |
  2. OUTPUT=$(pytest --color=yes --cov --cov-report=term | grep 'TOTAL' | awk '{print $(NF)}')
  3. echo $OUTPUT
  4. COVERAGE="${OUTPUT%\%}" # 删除百分号
  5. if (( COVERAGE < 80 )); then
  6. echo "代码覆盖率低于80%";
  7. exit 1;
  8. else
  9. echo "代码覆盖率为 $COVERAGE%";
  10. fi
  11. displayName: '运行 pytest'
英文:

You should switch to term output:

  1. - bash: |
  2. OUTPUT=$(pytest --color=yes --cov --cov-report=term | grep &#39;TOTAL&#39; | awk &#39;{print $(NF)}&#39;)
  3. echo $OUTPUT
  4. COVERAGE=&quot;${OUTPUT%\%}&quot; # Remove the percent sign
  5. if (( COVERAGE &lt; 80 )); then
  6. echo &quot;Code coverage is below 80%&quot;;
  7. exit 1;
  8. else
  9. echo &quot;Code coverage is $COVERAGE%&quot;;
  10. fi
  11. displayName: &#39;Run pytest&#39;

huangapple
  • 本文由 发表于 2023年7月7日 02:51:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76631761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定