Azure DevOps - Github 状态检查
Azure DevOps - Github status checks
我有 n+ github 个存储库,我想连接到 2 个单独的 Azure DevOps 管道。
- 我不想为每个回购使用 azure-pipelines.yaml,因为它对所有回购都是一样的。如果有任何更改,我宁愿在单个回购中进行更改,然后在其中的 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 section.
我怀疑我缺少一些 triggers/hooks 配置,我们将不胜感激。
要使用 GitHub 状态检查,
首先,为存储库创建一个管道并至少构建一次,以便将其状态发布到 GitHub,从而使 GitHub 知道管道的名称。
接下来,按照 GitHub 的文档在存储库设置中配置受保护的分支。
您可以关注此文档:Protected branches
如果您想使用触发器设置,我们建议您将您的 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"}'
{my-PAT} 是 personal access token,它的范围必须是 'repo:state'(或更多)
{commit-sha} 应该可以在运行时找到,查看 this doc 中的 pipeline/container 示例。我的案例是管道资源(不是存储库):
resources.pipeline.[别名].sourceBranch
resources.pipeline.[别名].sourceCommit
我想所有其他 {my-*} 值都很清楚。
成功请求后,我在可用状态检查列表中找到标题为default
的行。基于doc可以改
我有 n+ github 个存储库,我想连接到 2 个单独的 Azure DevOps 管道。
- 我不想为每个回购使用 azure-pipelines.yaml,因为它对所有回购都是一样的。如果有任何更改,我宁愿在单个回购中进行更改,然后在其中的 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 section.
我怀疑我缺少一些 triggers/hooks 配置,我们将不胜感激。
要使用 GitHub 状态检查, 首先,为存储库创建一个管道并至少构建一次,以便将其状态发布到 GitHub,从而使 GitHub 知道管道的名称。 接下来,按照 GitHub 的文档在存储库设置中配置受保护的分支。 您可以关注此文档:Protected branches 如果您想使用触发器设置,我们建议您将您的 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"}'
{my-PAT} 是 personal access token,它的范围必须是 'repo:state'(或更多)
{commit-sha} 应该可以在运行时找到,查看 this doc 中的 pipeline/container 示例。我的案例是管道资源(不是存储库):
resources.pipeline.[别名].sourceBranch
resources.pipeline.[别名].sourceCommit
我想所有其他 {my-*} 值都很清楚。
成功请求后,我在可用状态检查列表中找到标题为default
的行。基于doc可以改