Search code examples
tfsazure-devopstfsbuild

How to tag a build with it's pull request on TFS?


In VSTFS I'm trying to create a build tag that gets the source (pull request) from a merge. I've been trying to do it using variables such as those described by Microsoft in this link: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=designer%2Cbatch

Just so you can get a little more vision on the issue:

  • Someone creates a Pull Request (it has a hash of it's own);
  • The Pull Request is approved and commited;
  • There's a merge;
  • A build is triggered;
  • It's tagged.

Currently we're just using the BuildNumber variable on the tag, we want to add to it the source Pull Request ID.

Images:

Variable Input

Resulting Build Tag


Solution

  • When you tag the build you can use the variable System.PullRequest.PullRequestId, it returns the Pull Request Id.