简体   繁体   English

Azure Devops:如何配置我的管道脚本以触发具有不同 repo 的另一个管道?

[英]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.

相关问题 在发布管道中执行阶段时触发不同的存储库 - Azure DevOps - Trigger different repository when execute stage in a release pipeline - Azure DevOps 如何将 ACR 与 Azure devops 管道连接,以便每当 ACR azure devops 管道中有新图像时触发 - How to connect ACR with Azure devops pipeline such that whenever there is a new image in ACR azure devops pipeline trigger 如何根据提交消息触发 azure devops build pipeline? - How to trigger azure devops build pipeline based on the commit message? 如何使用 jquery 触发 Azure Devops 发布管道 - How to trigger Azure Devops release pipeline using jquery Azure Devops Release Pipeline 中针对不同分支的多个调度 - Multiple schedules in Azure Devops Release Pipeline for different branches Azure 插件的 devops 管道条件 - Azure devops pipeline condition of plugin Azure DevOps 发布管道中的 Bicep - Azure Bicep in DevOps release pipeline 在 Azure Devops YML 管道脚本中使用 boolean 变量作为小写字符串 - Use boolean variable as lowercase string in Azure Devops YML pipeline script 在 Azure Devops 中获取正在运行的 devops 管道实例 - Get running instances of devops pipeline in Azure Devops 在 Azure DevOps 中保护管道变量 - Securing Pipeline Variables in Azure DevOps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM