繁体   English   中英

Azure DevOps - Github 状态检查

[英]Azure DevOps - Github status checks

我有 n+ github 存储库,我想连接到 2 个单独的 Azure DevOps 管道。

  • 我不想在每个 repo 中使用 azure-pipelines.yaml,因为它们对所有人都是一样的。 如果有任何更改,我宁愿在单个 repo 中更改,然后在其中 n+ 中更改。
  • 我的目标是对我的所有 n+ 存储库的提交和 PR 进行 github 状态检查。
  • 管道本身托管在 github 中(如果这有什么不同的话)。

我当前在推送时触发的设置是以下列方式使用resources

resources: 
  repositories:
  - repository: self
    type: git
    name: woohoo/validation1
    trigger: none  # to avoid triggering the build for pipeline itself
  - repository: repo1
    type: githubenterprise
    name: woohoo/repo1
    endpoint: myendpoint
    trigger:  
      branches:
        include:
         - test/*
    pr: 
     branches:
      include:
       - '*' 
  - repository: repo2
    type: githubenterprise
    name: woohoo/repo2
    endpoint: myendpoint
    trigger:  
      branches:
        include:
         - test/*
    pr: 
     branches:
      include:
       - '*' 
  ...

这适用于触发构建并正确运行它们,但仍然缺少状态检查。 此外,在Require status checks to pass before merging 部分中编辑分支保护规则时,我没有看到管道。

我怀疑我缺少一些触发器/挂钩配置,任何帮助将不胜感激。

要使用 GitHub 状态检查,首先,为存储库创建一个管道并至少构建一次,以便将其状态发布到 GitHub,从而使 GitHub 知道管道的名称。 接下来,按照 GitHub 的文档在存储库的设置中配置受保护的分支。 您可以按照此文档: 受保护的分支如果您想使用触发器设置,我们建议您将 yaml 更改为:

 - repository: repo1
    type: githubenterprise
    name: woohoo/repo1
    endpoint: myendpoint
    trigger:  
      branches:
        include:
         - test/*
    pr: 
     branches:
      include:
       - '*'  

对于此类问题,我只找到了一种解决方案。 它是基于doc的直接 GitHub API 调用

curl \
   -X POST \
   -H "Accept: application/vnd.github.v3+json" \
   -u {my-name}:{my-PAT} \
   https://api.github.com/repos/{my-org}/{my-repo}/statuses/{commit-sha} \
   -d '{"state":"success", "description": "test status change"}'
  1. {my-PAT} 是个人访问令牌,它的 scope 必须是 'repo:state' (或更多)

  2. {commit-sha} 应该能够在运行时找到,请查看此文档,其中包含管道/容器的示例。 我的案例是管道资源(不是存储库):

    resources.pipeline..sourceBranch 资源.pipeline..sourceCommit

  3. 我想所有其他 {my-*} 值都很清楚。

在成功请求之后,我在可用状态检查列表中找到了标题为default的行。 根据文档,它可以更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM