Azure DevOps - Github 状态检查

标签 azure github azure-devops azure-pipelines pipeline

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

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

我当前在推送时触发的设置是按以下方式使用资源:

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:
       - '*' 
  ...

这对于触发构建并正确运行它们非常有效,但仍然缺少状态检查。此外,在需要在合并部分之前通过状态检查中编辑分支保护规则时,我没有看到管道。

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

最佳答案

对于此类问题,我只找到了一种解决方案。它是基于 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} 是 personal access token ,它的范围必须是“repo:state”(或更多)

  2. {commit-sha} 应该能够在运行时找到,查看this doc带有管道/容器的示例。我的案例是管道资源(不是存储库):

    resources.pipeline.[别名].sourceBranch

    resources.pipeline.[别名].sourceCommit

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

请求成功后,我在可用状态检查列表中找到了标题为 default 的行。基于doc可以更改。

关于Azure DevOps - Github 状态检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67090418/

相关文章:

git - 如何在 git 中 merge cherry-picked 提交?

github - Gulp不会在 Jenkins (Jenkins)工作

azure - 我们可以在发布管道 - Azure devOps 中发布工件吗?

azure - 在 Azure Devops 上的 cURL 请求中使用环境变量

Azure Devops 没有这样的文件或目录

azure - 有没有办法在使用当前 API 创建 Blob 时设置元数据,而不使用 Microsoft.Azure.Storage.Blob?

c# - 有没有办法使用最新的 .NET Core SDK 在 Azure 中创建具有诊断和身份配置的容器组

visual-studio - 发布成功但网站没有任何变化?

excel - 使用 github 存储 Excel 文件

azure - 有没有在 Azure 中的应用程序之间共享配置的好方法?