在 Azure DevOps 中创建“基于差异”的拉取请求门

问题描述 投票:0回答:1

我有一个门(构建验证/状态检查),它运行我编写的一些基准测试。基准测试运行新代码并返回新代码的总运行时间。

我不想使用“如果时间少于 10 秒”之类的硬编码阈值,而是希望将此门设为基于差异的指标,以查看新提出的代码与结果之间的运行时间差异百分比

main
该分支来自的分支提交(就像通常在代码覆盖率门中所做的那样)

是否有内置方法可以在 Azure DevOps 上创建“基于差异”的门?

azure-devops continuous-integration azure-pipelines pull-request
1个回答
0
投票

恐怕没有内置方法可以在Azure DevOps中制作“基于差异”的门。

解决方法是,可以通过分支策略中的Build Validation运行Pipeline,获取Pull Ruqeust预合并代码的运行时间和主分支的运行时间。最后通过自定义脚本获取百分比。

步骤如下:

Step1:创建Build Pipeline(YAML类型)并使用repo资源签出当前repo的主分支。

例如:

resources:
  repositories:
  - repository: mainbranchrepo
    type: git
    name: sqlite-dotnet-core.git
    ref: main
    

pool:
  vmImage: ubuntu-latest

steps:
- checkout: self
  path: s/PullRequest
- checkout: mainbranchrepo
  path: s/MainBranch

在这种情况下,一旦Pull Request触发管道,它将同时检出预合并分支和主分支。

Step2:添加在 Pull Request 分支和主分支上运行基准测试的步骤。然后你就可以收集基准测试的两次运行时间

Step3:添加自定义脚本以获取运行时间的百分比差异。

例如:

resources:
  repositories:
  - repository: mainbranchrepo
    type: git
    name: sqlite-dotnet-core.git
    ref: main


pool:
  vmImage: ubuntu-latest

steps:
- checkout: self
  path: s/PullRequest
- checkout: mainbranchrepo
  path: s/MainBranch
-  run benchmark tests on Pull Request Branch
-  run benchmark tests on Main Branch

- script: custom script to get the % result

第四步:添加构建验证分支策略以使用上面的 YAML 管道。

当 Pipeline 被 Pull Request 触发时,会显示以下分支:

注意:如果您需要在自定义脚本中使管道失败或将运行时值传递给下一个任务。您可以使用logging命令

© www.soinside.com 2019 - 2024. All rights reserved.