|
1 | 1 | --- |
2 | | -title: Deploy to different stages from multiple branches |
3 | | -description: Learn how to use Classic release pipelines to deploy to different stages from multiple branches. |
| 2 | +title: Deploy multiple branches to different stages |
| 3 | +description: Learn how to use Classic release pipelines to deploy from multiple branches to different stages. |
4 | 4 | ms.topic: tutorial |
5 | | -ms.date: 08/06/2024 |
| 5 | +ms.date: 03/23/2026 |
6 | 6 | monikerRange: "<=azure-devops" |
7 | 7 | "recommendations": "true" |
8 | 8 | --- |
9 | 9 |
|
10 | | -# Deploy to different stages from multiple branches using Classic release pipelines |
| 10 | +# Deploy multiple branches to different stages with Classic release pipelines |
11 | 11 |
|
12 | 12 | [!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)] |
13 | 13 |
|
14 | | -Classic release pipelines provide a convenient graphical user interface for setting up a continuous delivery solution for your application. Classic releases can be configured to trigger deployments automatically whenever a new artifact is available. Artifact filters can be used with release triggers to deploy from multiple branches. By applying artifact filters to specific branches, you can control deployment to particular stages based on your needs. |
15 | | - |
16 | | -In this article, you'll learn how to: |
17 | | - |
18 | | -> [!div class="checklist"] |
19 | | -> * Enable continuous deployment triggers. |
20 | | -> * Release from multiple branches. |
21 | | -> * Deploy to multiple stages. |
| 14 | +Classic release pipelines provide a graphical way to set up continuous delivery for your application. You can configure a release to trigger automatically when a new artifact is available, and then use artifact filters to map specific branches to specific stages. This approach lets you deploy each branch to the stage you intend. This article walks you through how to configure a Classic release pipeline that deploys to different stages based on the source branch. |
22 | 15 |
|
23 | 16 | ## Prerequisites |
24 | 17 |
|
25 | | -- An Azure DevOps organization and a project. Create an [organization](../../organizations/accounts/create-organization.md) or a [project](../../organizations/projects/create-project.md#create-a-project) if you haven't already. |
| 18 | +| **Product** | **Requirements** | |
| 19 | +|--------------------|-------------------| |
| 20 | +| **Azure DevOps** | - An [Azure DevOps organization](../../organizations/accounts/create-organization.md).<br> - An [Azure DevOps project](../../organizations/projects/create-project.md).<br> - A working pipeline set up for your repository to build your project and generate a pipeline artifact. [Create a Classic pipeline](create-classic-pipelines.md) if you don't have one already. | |
26 | 21 |
|
27 | | -- A working pipeline set up for your repository to build your project and generate a pipeline artifact. [Create your first pipeline](../create-first-pipeline.md) if you don't have one already. |
| 22 | +## Create a Classic release pipeline |
28 | 23 |
|
29 | | -## Create a release pipeline |
| 24 | +In this section, you create the base Classic release pipeline and configure the first stage (**Dev**). You add an artifact source, enable automatic release creation, and apply an artifact filter so this stage runs only when the build comes from the *Dev* branch. |
30 | 25 |
|
31 | 26 | 1. Sign in to your Azure DevOps organization, and then navigate to your project. |
32 | 27 |
|
33 | | -1. Select **Pipelines** > **Releases**. If this is your first release pipeline, select **New Pipeline**, otherwise select **New** > **New release pipeline**. |
| 28 | +1. Select **Pipelines** > **Releases**. |
| 29 | + |
| 30 | +1. Create a new Classic release pipeline: |
| 31 | + |
| 32 | + - If this is your first release pipeline, select **New Pipeline**. |
| 33 | + - If you already have release pipelines, select **New** > **New release pipeline**. |
| 34 | + |
| 35 | +1. In the template picker, select **Start with an empty job**. |
| 36 | + |
| 37 | +1. Under **Stages**, select the default stage and rename it to **Dev**. In the next steps, you configure this stage to deploy only when an artifact is produced from the *Dev* branch. |
34 | 38 |
|
35 | | -1. When prompted to select a template, select **Start with an empty job**. |
| 39 | + :::image type="content" source="media/rename-stage-classic-release.png" alt-text="A screenshot displaying how to rename a stage in a Classic release pipeline."::: |
36 | 40 |
|
37 | | -1. Under **Stages**, select the stage and rename it to **Dev**. The following steps show how to configure this stage to be triggered when an artifact is published from the *Dev* branch. |
| 41 | +1. Under **Artifacts**, select **Add**. |
38 | 42 |
|
39 | | - :::image type="content" source="media/dev-stage.png" alt-text="A screenshot displaying how to rename a stage in a Classic release pipeline."::: |
| 43 | +1. Configure the artifact source: |
40 | 44 |
|
41 | | -1. Under **Artifacts**, select **Add** to add an artifact. Specify your **Source type** and fill out the required fields (these vary based on the selected source type). Select **Add** when you're done. |
| 45 | + - Select your **Source type**. |
| 46 | + - Complete the required fields for that source type, such as project, pipeline, and default version. |
| 47 | + - Select **Add**. |
42 | 48 |
|
43 | | - :::image type="content" source="media/add-artifact.png" alt-text="A screenshot that shows how to add an artifact to a Classic release pipeline."::: |
| 49 | + :::image type="content" source="media/add-artifact-to-classic-release.png" alt-text="A screenshot that shows how to add an artifact to a Classic release pipeline."::: |
44 | 50 |
|
45 | | -1. Select the **Continuous deployment trigger** icon, and then enable the **Continuous deployment trigger** to create a release whenever a new artifact is available. |
| 51 | +1. Select the **Continuous deployment trigger** icon on the artifact, and then turn on **Continuous deployment trigger** to create a release whenever a new artifact is available. |
46 | 52 |
|
47 | | - :::image type="content" source="media/enable-continuous-deployment-trigger.png" alt-text="A screenshot displaying how to enable the continuous deployment trigger."::: |
| 53 | + :::image type="content" source="media/enable-continuous-deployment-trigger.png" alt-text="A screenshot displaying how to enable the continuous deployment trigger in a Classic release pipeline."::: |
48 | 54 |
|
49 | | -1. In the Dev stage, select the **Pre-deployment conditions** icon and set the deployment trigger to **After release**. This will trigger a deployment to this stage whenever a new release is created. |
| 55 | +1. In the **Dev** stage, select the **Pre-deployment conditions** icon. |
50 | 56 |
|
51 | | - :::image type="content" source="media/predeployment-trigger.png" alt-text="A screenshot that shows how to configure the pre-deployment conditions."::: |
| 57 | +1. Set **Deployment trigger** to **After release** so the stage starts automatically whenever a new release is created. |
52 | 58 |
|
53 | | -1. while still in **Pre-deployment conditions**, enable **Artifact filters**, select **Add**, and then specify the artifact you selected earlier and set the **Build branch** to *Dev*. |
| 59 | +1. Still in **Pre-deployment conditions**, configure branch-based filtering: |
| 60 | + |
| 61 | + - Turn on **Artifact filters**. |
| 62 | + - Select **Add**. |
| 63 | + - Select the artifact you added earlier. |
| 64 | + - Set **Build branch** to *Dev*. |
| 65 | + |
| 66 | + With this filter in place, the **Dev** stage deploys only when the release is created from a build of the *Dev* branch. |
| 67 | + |
| 68 | + :::image type="content" source="media/configure-deployment-conditions-development-stage.png" alt-text="A screenshot displaying how to set up the pre-deployment conditions in a Classic release pipeline."::: |
54 | 69 |
|
55 | | - :::image type="content" source="media/predeployment-conditions-artifact-filters.png" alt-text="A screenshot displaying how to set up the Artifact filters in Pre-deployment conditions."::: |
56 | 70 |
|
57 | 71 | ## Add a new stage |
58 | 72 |
|
| 73 | +In this section, you add a second stage (**Prod**) to the same release pipeline and configure it to deploy only when artifacts are built from the *main* branch. This lets you keep branch-to-stage routing consistent across environments. |
| 74 | + |
59 | 75 | 1. Sign in to your Azure DevOps organization, and then navigate to your project. |
60 | 76 |
|
61 | | -1. Select **Pipelines** > **Releases**, select your release pipeline, and then select **Edit**. |
| 77 | +1. Select **Pipelines** > **Releases**, open the release pipeline you created earlier, and then select **Edit**. |
62 | 78 |
|
63 | | -1. Under **Stages**, select **Add** > **New stage** to add a new stage. |
| 79 | +1. Under **Stages**, select **Add** > **New stage**. |
64 | 80 |
|
65 | | -1. Select **Start with an empty job** when prompted to select a template. |
| 81 | +1. In the template picker, select **Start with an empty job**. |
| 82 | + |
| 83 | +1. Select the new stage and rename it to **Prod**. In the next steps, you configure this stage so it deploys only when the artifact comes from the *main* branch. |
66 | 84 |
|
67 | | -1. Select your new stage and rename it to **Prod**. The following steps show how to configure this stage to trigger when an artifact is published from the *main* branch. |
| 85 | +1. In the **Prod** stage, select the **Pre-deployment conditions** icon. |
68 | 86 |
|
69 | | -1. Select your *Prod* stage, select the **Pre-deployment conditions** icon, and set the deployment trigger to **After release**. This ensures deployment to this stage whenever a new release is created. |
| 87 | +1. Set **Deployment trigger** to **After release** so this stage can start automatically when a new release is created. |
70 | 88 |
|
71 | | -1. Select the toggle button to enable **Artifact filters**. Select **Add**, and then specify the artifact you selected earlier and set the **Build branch** to *main*. |
| 89 | +1. Still in **Pre-deployment conditions**, configure branch-based filtering for production: |
72 | 90 |
|
73 | | - :::image type="content" source="media/predeployment-conditions-prod.png" alt-text="A screenshot displaying how to configure predeployment conditions for the Prod stage."::: |
| 91 | + - Turn on **Artifact filters**. |
| 92 | + - Select **Add**. |
| 93 | + - Select the same artifact source you configured earlier. |
| 94 | + - Set **Build branch** to *main*. |
| 95 | + |
| 96 | + With this filter in place, the **Prod** stage deploys only when the release is created from a build of the *main* branch. |
| 97 | + |
| 98 | + :::image type="content" source="media/configure-deployment-conditions-production-stage.png" alt-text="A screenshot displaying how to configure pre-deployment conditions for the production stage in a Classic release pipeline."::: |
74 | 99 |
|
75 | 100 | ## Deploy to a specific stage |
76 | 101 |
|
77 | | -Now that you've set up your stages, every time a new artifact is available, the release pipeline will detect which branch triggered the build and deploy only to the appropriate stage. |
| 102 | +At this point, your release pipeline is configured to route deployments by branch: artifacts from the *Dev* branch deploy to the **Dev** stage, and artifacts from the *main* branch deploy to the **Prod** stage. Use the following checks to validate that the branch filters are working as expected. |
| 103 | + |
| 104 | +1. Trigger a build from the *Dev* branch so a new artifact version is published. |
| 105 | + |
| 106 | +1. Open **Pipelines** > **Releases**, and then open the newly created release. |
| 107 | + |
| 108 | +1. Verify that the **Dev** stage starts (or is queued), and that the **Prod** stage is skipped because the artifact branch doesn't match its filter. |
| 109 | + |
| 110 | +1. Trigger a second build from the *main* branch. |
| 111 | + |
| 112 | +1. Open the new release and verify the opposite behavior: the **Prod** stage starts, and the **Dev** stage is skipped. |
| 113 | + |
| 114 | +1. If a stage doesn't behave as expected, open that stage's **Pre-deployment conditions** and confirm the **Artifact filters** branch value and selected artifact source. |
| 115 | + |
| 116 | +By validating both branch paths, you can confirm that each environment deploys only from the branch intended for that stage. |
| 117 | + |
| 118 | +## Related content |
78 | 119 |
|
79 | | -:::image type="content" source="media/deploy-to-specific-stage.png" alt-text="A screenshot displaying deployment to a specific stage."::: |
| 120 | +- [Create a multi-stage release pipeline](define-multistage-release-process.md) |
80 | 121 |
|
81 | | -## Related articles |
| 122 | +- [Use variables in Classic release pipelines](variables.md) |
82 | 123 |
|
83 | | -- [Artifact sources](artifacts.md) |
84 | | -- [Release triggers](triggers.md) |
85 | 124 | - [Deploy pull request Artifacts](deploy-pull-request-builds.md) |
0 commit comments