Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get target branch from a pull request using azure devops api or other methods?

I'm trying to make a single build pipeline for 3 env (dev, qa, prod) but with ability to choose which one to build from.

The idea is to keep the pipeline on prod branch or another repo, and not having it in every env. The issue now is that on a PR it will start the pipeline only on master(prod) branch as it shall contain the yml file.

Is there a way to get the PR target branch in order to add additional conditions for PR triggers?

like image 612
dAn Avatar asked Jul 13 '20 10:07

dAn


People also ask

How do I change the target branch in pull request Azure DevOps?

Go to the pull request and click the ellipsis button and select Edit. From here you can change the target branch for the pr.

How do I use Azure DevOps pull request?

From the Pull Requests view, select New Pull Request. Select the source and target branches, enter a title and optional description, and select Create. After the PR is created, select Open in browser to open the new PR in the Azure DevOps web portal.

How do I see Pull Requests in Azure DevOps?

Select View > Team Explorer to open Team Explorer. You can also press Ctrl+\, Ctrl+M. From Home, select Pull Requests to view lists of PRs opened by you or assigned to you. To view the PR list in the Azure DevOps web portal, select Actions and then select Open in browser.


1 Answers

how to get target branch from a pull request using azure devops api or other methods?

Agree with Yan Sklyarenko. Azure devops provides us with some predefined variables, like:

System.PullRequest.IsFork
System.PullRequest.PullRequestId
System.PullRequest.PullRequestNumber
System.PullRequest.SourceBranch
System.PullRequest.SourceRepositoryURI
System.PullRequest.TargetBranch

To get the target branch from a pull request, we could use the predefined variable System.PullRequest.TargetBranch.

So, we could use this predefined variable as condition:

condition: and(succeeded(), eq(variables['System.PullRequest.TargetBranch'], 'refs/heads/master'))
like image 125
Leo Liu-MSFT Avatar answered Sep 28 '22 09:09

Leo Liu-MSFT