I have a simple pipeline on Azure dev ops that has 4 jobs
That works. At this moment version bump does only 'patch' every time as a PR is made to the master branch. So it releases only patch versions... I have a custom condition for that:
contains(variables['Build.SourceBranch'], 'refs/heads/master')
. Well what I want is to add one more condition here that decides to bump version dynamically as patch, major or minor for example... So I was thinking to get that parameter from the pull request title or description sth like that..:
contains(variables['Build.PR.Title'], 'patch')
contains(variables['Build.PR.Title'], 'major')
contains(variables['Build.PR.Title'], 'minor')
That is indeed 3 different jobs that will fire if the pr title has 'patch', 'major' or 'minor'.. Is it possible to do something like that or is there a easier way?:)
Thanx in advance!
Azure Devops pipeline does not pass the title of prs. You can find here the predefined variables: Use predefined variables. To get detailed information of active Pull Request you may use Rest Api Pull Requests - Get Pull Request By Id with System.PullRequest.PullRequestId
. As example to get the title:
$user = ""
$token = "$(System.AccessToken)"
$teamProject = "$(System.TeamProject)"
$PRId = "$(System.PullRequest.PullRequestId)"
$orgUrl = "$(System.CollectionUri)"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$uriGetActivePr = "$orgUrl/$teamProject/_apis/git/pullrequests/$PRId"
$resultPR = Invoke-RestMethod -Uri $uriGetActivePr -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Write-Host "##vso[task.setvariable variable=Custom.PRTitle]"$resultPR.title
Then you can use your new variable in your conditions, like:
and(contains(variables['Build.SourceBranch'], 'refs/heads/master'), contains(variables['Custom.PRTitle'], 'patch'))
Thanx for the reply! That works!:)