Trigger a Pipeline from an Azure DevOps Pipeline

2 minute read

In some situations,
it can be useful to trigger an Azure DevOps pipeline from a pipeline.
Triggering a pipeline can be done via the API and trough PowerShell. You can
write your own script file and use the PowerShell tasks but there is also a
custom task in the Azure DevOps marketplace:

With this task you can trigger a build or release pipeline from another pipeline within the same project or organization but also in another project or organization.

Personal Access Token

To get
started a Personal Access Token is needed with the appropriate rights to execute
pipelines. To generate a new Personal Access Token follow the below guide:

Give the personal
access token the following rights depending on your scenario:

  • Triggering a Release:
    • Release – Read, write & execute
    • Build - Read & Execute (Needed for reading the artifacts)
  • Triggering a Build:
    • Build - Read & execute

Copy the token for later use.

Configure extension

When you
have installed the extension, you can start by altering a pipeline from where
you want to trigger a different pipeline.

  • Add
    a new task to the pipeline by clicking in “+” icon.
  • In
    the task window search for “Trigger” and select the task “Trigger Azure DevOps
    pipeline”.
  • In
    the task click on “New” next to Azure DevOps Service connection to create a new
    connection.
  • In the new service connection window fill in all the correct properties.
    • Connection name: The name for the connection
    • Organization URL: The URL of the organization for Azure DevOps this would be https://dev.azure.com/[organization name]
    • Release URL: The URLfor the release API for Azure DevOps this would be
      https://vsrm.dev.azure.com/[organization name]
    • Personal Access Token: The personal access token that needs to be used.
  • In
    the task choose the right options. The field for the project, build and release
    definitions should be filled in for you.

When you want
to trigger a release for a specific version make sure to fill in the build
number. When left empty the extension will use the latest version by default.

Besides that,
it is also possible to trigger a build for a specific branch. When you want to
make use of that option make sure you fill in the “Branch” property.