1

Did someone manage to integrate Azure DevOps in Sentry (sentry.io)? I stuck on "Associate commits with a Release" (see: https://docs.sentry.io/workflow/releases/?platform=browser#associate-commits-with-a-release)

I can not figure out a way how I can tell Sentry (by API) which commit ids are associated with a current release/deploy. How can I add a task to the pipeline which will post the commit ids to Sentry API? Or is there some other way to do it?

riQQ
  • 9,878
  • 7
  • 49
  • 66
Darth Sonic
  • 105
  • 7
  • Have you looked into a Powershell task and then use the Azure DevopsAPI to query the data? https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-5.1 – Josh Nov 14 '19 at 14:55

1 Answers1

2

In azure devops, the Powershell task also support curl. So, you can execute the api in powershell task of VSTS pipeline directly.

In release pipeline, there has a pre-defined release variable, it stores the commit id which is associated with the current release pipeline: $(Release.Artifacts.{alias}.SourceVersion). Here alias is the artifacts name, and you can get it by getting $(Release.PrimaryArtifactSourceAlias).

First, create variables like this:

enter image description here

Then you can apply the variable $(id) into that API, and execute the api in powershell task:

"refs": [{
 "commit":"$(id)"
 }]

Now, the commit id could be packed into the body of this api, and send to the Sentry server.


If there has multiple commits associate with this release, since the variable $(Release.Artifacts.{alias}.SourceVersion) I mentioned above only store the latest commit message, here you may need add additional scripts to get what you want by Build id.

In release pipeline, with $(Build.BuildId) you can get the corresponding buildid which associate with this release. And then, you could get the commits(changes) by using this API:

GET https://dev.azure.com/{organization}/{project}/_apis/build/changes?fromBuildId={fromBuildId}&toBuildId={toBuildId}&api-version=5.1-preview.2

enter image description here

You could apply these powershell script into your task without change anything because this script is universal among powershell-ise, powershell command line and powershell task in VSTS.

$token = "{PAT token}"
$url="https://dev.azure.com/{org name}/{project name}/_apis/build/changes?fromBuildId={id1}&toBuildId={id2}"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get
Write-Host "results = $($response.value.id | ConvertTo-Json -Depth 100)"

Now, you could get the list of commits which associate with the build and corresponding release.

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • My problem is, that a release has multiple commits (and therefore commit ids) and to use the sentry feature I have to associate them all to a release. But I can not figure out a variable that returns all commit ids. – Darth Sonic Nov 18 '19 at 09:25
  • It would be know problem to do this association on application side (backend code) if there is a possibility to read the commit ids of a build (by name) for example. – Darth Sonic Nov 18 '19 at 09:26
  • @DarthSonic. It can be achieved, but little confused. Either build or release, there's no directly variable can get all associate commits. In build pipeline, `Build.SourceVersion` can get the commit of build. BUT, it only restore the **latest commit**. To get all commits, you need use this [api](https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/get%20changes%20between%20builds?view=azure-devops-rest-5.1). It will cause another issue: the commits between 2 builds not always equal with the commits which associate with current build. It depend on your actual build pipeline. – Mengdi Liang Nov 18 '19 at 10:15
  • @DarthSonic. I update more details into my answer, please check that. – Mengdi Liang Nov 18 '19 at 10:15