Pletmeister
Pletmeister

Reputation: 1

Azure DevOps API run single stage from multistage pipeline

I am in a situation where I have several pipelines, from which the output will be a complete solution. So I will be triggering those pipelines from a "mother" pipeline using the Azure DevOps REST API. I am succeeding to queue the pipeline and run it. But this pipeline is multi stage (DTAP).

I would like to run only a single stage. Does anyone know where I should look or what I should do?

Upvotes: 0

Views: 2891

Answers (4)

P-L
P-L

Reputation: 533

You could use the method described here: https://stackoverflow.com/a/73200692/511105

ie.

a) You define a parameter per stage with a default false value.

 parameters:
 - name: deployDEV
   displayName: Deploy to DEV
   type: boolean
   default: false

b) You bind it as an equality comparator in its associated stage condition.

  condition: eq(${{ parameters.deployDEV }}, true)

c) Then, using the REST API, in the BODY construction, set the desired parameter to true:

> "
>     {
>         "stagesToSkip": [],
>         "resources": {
>             "repositories" : {
>                 "self": {
>                     "refName": "$refName"
>                 }
>             }
>         },
>         "templateParameters": {
>             "deployDEV": "true"
>         },
>         "variables": { }
>     } "

The other option would be to have a function building the string array of all the pipeline associated stages minus the one you want to deploy on. Then, pass the results in the same way inside the BODY message inside the stagesToSkip": [] value.

Upvotes: 0

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31075

Agree with @jessehouwing. You can specify the conditions under which each stage runs. By default, a stage runs if it does not depend on any other stage, or if all of the stages that it depends on have completed and succeeded. You can customize this behavior by forcing a stage to run even if a previous stage fails or by specifying a custom condition.

Check the following example of using a custom condition:

stages:
- stage: A

- stage: B
  condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))

Upvotes: 1

jessehouwing
jessehouwing

Reputation: 115017

There is no direct way to trigger only specific stages, but you can decorate each stage with a condition. And you can pass parameters (variable values) to a pipeline at queue time (also through the API).

By adding and setting the variables, you can control the condition and thus control which stage to run.

Be careful with dependencies though, any stage you depend on of course has to run as well.

Upvotes: 1

Krzysztof Madej
Krzysztof Madej

Reputation: 40879

This is no possible at the moment. Please check this topic - How to use ADO REST APIs to run one stage in a multi-stage YAML pipeline?

Currently no such an API to trigger the specific stage in a multi-stage YAML pipeline.

However YAML-based multi-stage pipelines can now be managed from the command line by using the az pipelines command. For example, you can setup and manage pipelines interactively from the CLI, or automate the entire setup using a script, but seems still cannot trigger the specific stage.

Here you have a feature request - REST APIs to trigger a specific stage in multi-stage YAML pipeine.

Upvotes: 0

Related Questions