我们在 Azure Devops 中使用 yaml 管道和模板。要求是确定使用模板的所有管道是否都在运行所需的一组步骤?除了手动监控,还有什么方法可以确认这一点。
如果可以添加条件检查,以便我们可以检查特定任务是否存在,那将会很有用。
举例说明,假设一个模板有 4 个任务,用于运行 4 种不同类型的测试。使用此模板创建多个管道。他们可以选择通过打开这些测试来运行这些测试(在输入参数中设置 Yes/No 值)。我们需要检查并验证所有管道是否都在运行所有这 4 个测试。
答案 0 :(得分:0)
没有简单的方法可以做到这一点,因为我们无法通过 REST API 或任何其他方式获取有关使用过的 teplates 的详细信息。您可以做的是尝试对此进行一些模板化。所以首先你需要创建一个模板,如:
paramaters:
- name: repositoryName
type: string
default: 'self'
- name: pipelinePath
type: string
default: '' # if your pipeline file has always the same name you can put it here and do not set calling pipeline
jobs:
- job: '${{ parameters.repositoryName }}' # please easnure that you repository name is a valid job name
dependsOn: []
steps:
- checkout: ${{ parameters.repositoryName }}
- pwsh: |
Here you should use yq tool to extract steps which uses your template
Then manipulate it to be sure that it checks you conditions
And then send some alerts to slack or wahtever you want
然后您可以从管道中调用它,例如:
parameters:
- name: repositories
type: object
default:
- RepoA
- RepoB
- list all your repos here
resources:
repositories:
- repository: RepoA
type: git
name: RepoA
- repository: RepoB
type: git
name: RepoB
- list the same repos here to be sure you have permission to use them in the pipeline
jobs:
# I assumed that `pipelinePath` is always the same and set as default an thus we can use each expression. If not you will have to call it one by one
- ${{ each repository in parameters.repositoryName }}:
- template: template.yml
paramaters:
repositoryName: ${{ repository }}
这是潜在的解决方案。我不能提供完整的,但我认为这个想法很清楚。我建议使用 yq tool 但你可以使用任何你想要的东西来帮助你验证模板是否按预期使用。此外,您可以设置 cron 作业以使其按计划运行。