user8981417
user8981417

Reputation: 37

Combine pipelines into one

We have 2 pipelines

Pipeline 1:

Pipeline 2:

Goal is to combine these 2 pipelines into 1 or have it such a way that with one click both the pipelines will run where Pipeline 1 starts and then Pipeline 2 starts. What would be the best way to achieve this? Note that the Pipeline 1 is not considered complete as the .exe is running.

Upvotes: 0

Views: 3235

Answers (3)

DreadedFrost
DreadedFrost

Reputation: 2978

If you already have both pipelines configured and running separately and that is the desired state then have one pipeline completion trigger the next one. Can do this by using Pipeline Triggers

resources:
  pipelines:
  - pipeline: Pipeline1 # Name of the pipeline resource
    source: Pipeline1Name # Name of the pipeline referenced by the pipeline resource
    trigger: 
      branches:
      - releases/*
      - master

Pipeline1 is the name that your YAML will used to refer to the pipeline resource similar to a template in a another repository.

Source will be the name of the Pipeline as defined in your Azure Devops.

Upvotes: 0

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30383

You can try below workaround to combine the 2 pipelines into 1.

In the pipeline 1, you can open another command terminal to Start the .exe. For below example using Start-Process in powershell script:

When the powershell task finish executing below command, the dotnet run command will be executed in a new poweshell window and the pipeline will continue to execute the following tasks.

Start-Process powershell  -ArgumentList "dotnet run ..."

Then you can add PowerShell on target machines or SSH Deployment task in pipeline 1 to run the test script on server 2

See below simple example:

steps:

- powershell: |
    Start-Process powershell -ArgumentList "dotnet run ..."

- task: PowerShellOnTargetMachines@3
  inputs:
    Machines: 'server2'
    UserName: 'userName'
    UserPassword: '123456'
    InlineScript: |
      # Write your powershell commands here.
     
- powershell: |
    Stop-Process -Name processName
  

Upvotes: 0

Krzysztof Madej
Krzysztof Madej

Reputation: 40919

One option would be leave it as it is and add step in pipeline 1 to trigger pipeline 2 over REST API

https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=5.0

with this body

{
    "definition": {
        "id": 217
    },
    "sourceBranch": "refs/heads/master",
    "sourceVersion": "",
    "reason": 1,
    "demands": [],
    "parameters": "{\"system.debug\":\"true\"}"
}

(here you have an example how to do this from powershell task)

or with this extension Trigger Azure DevOps Pipeline

You can also try to combine these two pipeline into one useing stages. To run both stages in parallel you need to have them independent, like this:

stages:
- stage: FunctionalTest
  jobs:
  - job:
    ...

- stage: AcceptanceTest
  dependsOn: []    # this removes the implicit dependency on previous stage and causes this to run in parallel
  jobs:
  - job:
    ...

then if you trigger pipeline, both stages will run.

Third options is to use pipeline triggers but for this approach I would recommend for you create two stages in first pipeline and use stage filter.

Upvotes: 1

Related Questions