Created Azure pipeline yaml file in a topic branch, can i run it from the topic branch?

Viewed 2420

This may be a silly question, but I am writing a pipeline that will handle some automated testing. I am developing the yaml pipeline in a feature branch. Is there a way to run this pipeline in Azure Dev ops, or is the only way to submit a pull request and merge into master on each iteration?

3 Answers

When you run a DevOps pipeline, you choose a branch to execute the pipeline for. The azure-pipelines.yaml file in that branch is the one that will be executed by default. So in your scenario above, if you had an azure-pipelines.yaml file in the master branch, and a different version of azure-pipelines.yaml in a feature branch, the version that gets executed will be determined by which branch you're running the pipeline for.

You can define your pipeline on any branch you want and then if you select to create a pipeline from Existing Azure Pipelines YAML file you can choose your branch and select this file:

enter image description here

Another option would be adding condition to your main build to run specific stage only for feature branches if you have some naming convention applied:

variables:
  isFeature: $[contains(variables['Build.SourceBranch'], 'feature')]

stages:
- stage: A
  jobs:
  - job: A1
    steps:
      - script: echo Hello Stage A!

- stage: B
  condition: and(succeeded(), eq(variables.isFeature, true))
  jobs:
  - job: B1
    steps:
      - script: echo Hello Stage B!
      - script: echo $(isMain)

You can trigger to run a pipeline from any branch, not just master. You can specify which branches you are interested in under the trigger field :

trigger:
  branches:
    include:
    - master
    - feature/*
    - releases/*
    exclude:
    - releases/old*

If you look at this code, the above will trigger the build pipeline for branches master, any branch inside your feature folder (ex : feature/yo-currentFeature) and any under your releases folder. However no bulid pipeline will run if changes are made to releases/old branches. For more info on Triggers see : https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#ci-triggers

https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#pr-triggers

Once you add your feature branch under trigger:branches, any commits OR PRs you make to your feature branch will automatically trigger a build pipeline

(PS : goes without saying, but make sure your feature branch also contains your pipeline yml file)

Related