[英]Azure Devops: how configure my pipeline script to trigger another pipeline with different repo?
I have my own pipeline p-A with repository r-A , and pipeline p-B with another repo r-B .我有自己的管道p-A和存储库r-A ,以及管道p-B和另一个存储库 r -B 。
I want to update the pipeline script for p-A only, to trigger the p-B actively, without any modification in p-B .我只想更新p-A的管道脚本,以主动触发p-B ,而不对p -B 进行任何修改。
Below is the yaml pipeline script for p-B , which is already set up to run with schedule下面是p-B的 yaml 管道脚本,它已经设置为按计划运行
pool:
name: 'workflow_test_pool'
schedules:
- cron: "0 19 * * *"
displayName: run test every day at 8PM CET
branches:
include:
- main
always: true
trigger: none
jobs:
- job:
timeoutInMinutes: 30
steps:
- script: |
python -m pytest tests/ -s
displayName: 'Run the test'
below is the pipeline script main.yaml for p-A下面是p-A的管道脚本main.yaml
pool:
name: 'workflow_test_pool'
stages:
#########################
- template: pipeline2/p1.yaml
############################
- template: pipeline2/p2.yaml
parameters:
dependsOn:
- FirstPipeline
so the question is, how to trigger the pipeline p-B in pipeline2/p2.yaml (from p-A )?所以问题是,如何在pipeline2/p2.yaml中触发管道p-B (来自p-A )?
You can create PowerShell script task as the last step of the pipeline to trigger pipeline pB through REST API. You will have to maintain Personal Access Token, ideally as secret variable.您可以创建 PowerShell 脚本任务作为管道的最后一步,通过 REST API 触发管道 pB。您必须维护个人访问令牌,最好作为秘密变量。
REST API call you will use: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1 REST API 呼叫您将使用: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1
Detailed step-by-step guide: https://blog.geralexgr.com/cloud/trigger-azure-devops-build-pipelines-using-rest-api详细的分步指南: https://blog.geralexgr.com/cloud/trigger-azure-devops-build-pipelines-using-rest-api
Azure DevOps supports multiple repositories checkout, you can just reference resources function in your YAML script and call another repository to trigger from the pipeline. Azure DevOps 支持多个存储库检出,您可以在 YAML 脚本中引用资源 function 并调用另一个存储库从管道中触发。
YAML code:- YAML 代码:-
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
pool:
vmImage: ubuntu-latest
workspace:
clean: all
resources:
repositories:
- repository: repo_a
type: git
name: InternalProjects/repo_a
trigger:
- main
- release
- repository: repo_b
type: git
name: InternalProjects/repo_b
trigger:
- main
steps:
- checkout: repo_a
- checkout: repo_b
- script: dir $(Build.SourcesDirectory)
I am running this pipeline from repo_a and the repo_a and repo_b both ran successfully like below:-我正在从 repo_a 运行此管道,并且 repo_a 和 repo_b 都成功运行,如下所示:-
Output:- Output:-
You can directly run any task from pipeline with multiple repositories like below:-您可以直接从具有多个存储库的管道运行任何任务,如下所示:-
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
pool:
vmImage: ubuntu-latest
workspace:
clean: all
resources:
repositories:
- repository: repo_a
type: git
name: InternalProjects/repo_a
trigger:
- main
- release
- repository: repo_b
type: git
name: InternalProjects/repo_b
trigger:
- main
steps:
- checkout: repo_a
- checkout: repo_b
- task: AzureCLI@2
inputs:
azureSubscription: 'Subscription-name(sub-id)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'az resource list --location uksouth'
Output:- Output:-
References:-参考:-
Check out multiple repositories in your pipeline - Azure Pipelines | 检查管道中的多个存储库 - Azure Microsoft Learn
微软学习
Trigger azure Devops pipeline from another repository - GeralexGR 从另一个存储库触发 azure Devops 管道 - GeralexGR
Multiple Repositories in a Single Azure Pipeline - DEV Community 单个 Azure 管道中的多个存储库 - DEV Community
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.