我有 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"}'
{my-PAT} 是 personal access token ,它的范围必须是“repo:state”(或更多)
{commit-sha} 应该能够在运行时找到,查看this doc带有管道/容器的示例。我的案例是管道资源(不是存储库):
resources.pipeline.[别名].sourceBranch
resources.pipeline.[别名].sourceCommit
我想所有其他 {my-*} 值都很清楚。
请求成功后,我在可用状态检查列表中找到了标题为 default
的行。基于doc可以更改。
关于Azure DevOps - Github 状态检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67090418/