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?
Go to the pull request and click the ellipsis button and select Edit. From here you can change the target branch for the pr.
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.
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.
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'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With