简体   繁体   中英

How to trigger Azure devops pipeline from different project within same organization using stage/resource?

I want to trigger a Test pipeline from a stage of Main pipeline, both the pipelines are present in different projects within the same organization. I am able to trigger the pipeline using the resource option but the problem is it triggers the Test pipeline when Main pipeline finishes successfully but I want to trigger the Test pipeline in between run of Main pipeline using an stage. Is it possible to achieve this using any feature of Azure Devops?



For now I am adding this resource in Test pipeline yaml to trigger after Main pipeline.

resources:
  pipelines:
  - pipeline: Test-Repo 
    source:  Test # Test pipeline from different project
    project: private 
    trigger: true # enable the trigger

As a workaround, you can trigger the needed build through REST API. Check this: Powershell to trigger a build in Azure DevOps

A good approach is using Extension "Trigger Build Task": https://marketplace.visualstudio.com/items?itemName=benjhuser.tfs-extensions-build-tasks&targetId=ca4e4e67-3099-4c62-9ea9-bef80e0cc70a&utm_source=vstsproduct&utm_medium=ExtHubManageList

My main Pipeline is in Project A with two stages:

trigger:
- none

pool:
  vmImage: ubuntu-latest

stages:

    - stage: A
      displayName: A stage
      jobs:
      - job: A
        displayName: A
        steps:
          - task: TriggerBuild@4
            inputs:
              definitionIsInCurrentTeamProject: false
              tfsServer: '{Org URL}'
              teamProject: '{Project B Name}'
              buildDefinition: '213'
              queueBuildForUserThatTriggeredBuild: false
              ignoreSslCertificateErrors: false
              useSameSourceVersion: false
              useCustomSourceVersion: false
              useSameBranch: false
              waitForQueuedBuildsToFinish: false
              storeInEnvironmentVariable: false
              authenticationMethod: 'Personal Access Token'
              password: '{PAT}'
              enableBuildInQueueCondition: false
              dependentOnSuccessfulBuildCondition: false
              dependentOnFailedBuildCondition: false
              checkbuildsoncurrentbranch: false
              failTaskIfConditionsAreNotFulfilled: false
    
    - stage: B
      displayName: B stage
      dependsOn: A
      jobs:
      - job: 
        steps:
        - bash: echo "B"

在此处输入图像描述

在此处输入图像描述

Run Main Pipeline in Project A:

在此处输入图像描述

Test Pipeline in Project B is triggered at Main Pipeline Stage A:

在此处输入图像描述

Test Pipeline in Project B.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM