A small Azure function that, when it receives a PR updated to Closed state webhook from Azure Devops, will create a realease using the latest successful build for that PR.
After you have deployed OnPullRequest.csproj to an Azure Function, each devops project that you want to handle must have three configuration values set for it:
<ProjectName>:PersonalAccessToken
- The personal access token to be used to access devops. The PAT needs theBuild (Read)
andRelease (Read, Write, & Execute)
permissions. Further information on creating a PAT can be found here.<ProjectName>:DevopsBaseUrl
- The base url for your DevOps environment, usually in the form ofhttps://dev.azure.com/Organization/
.<ProjectName>:ReleaseDefinitionId
- The identifier of the release definition you want to trigger. This can be found in the URL of your releases page, proceed bydefinitionId=
.
So for https://dev.azure.com/fabrikamorganization/fabrikamproject, you might see the following configuration values:
"fabrikamproject:PersonalAccessToken": "zumbevdob60j8xtiw3t4np4z0rmmg00b5efdezr2rjyqnm94uxx6",
"fabrikamproject:DevopsBaseUrl": "https://dev.azure.com/fabrikamorganization/",
"fabrikamproject:ReleaseDefinitionId": 3
Finally, on your DevOps instance, create a Webhook to trigger on the "Pull request updated" event, targeting your Azure Function. All
must be selected for Resource details to send
. You may also wish to consider including a function key to prevent malicious users from running your function.