Archimedes Trajano
Archimedes Trajano

Reputation: 41440

How do you get the version for a the source repos for a given build?

I have a pipeline that has

resources:
  repositories:

In the GUI I can get the commit hash at the time the pipeline is run

enter image description here

How would I get that through CLI (or REST API if not possible on CLI)

From the console, it appears to get it using a /Contribution/HierarchyQuery

Upvotes: 0

Views: 1973

Answers (2)

wade zhou - MSFT
wade zhou - MSFT

Reputation: 8310

You can use the rest api which is not document:

GET https://dev.azure.com/{Organization}/{Project}/_build/results?buildId={Build ID}&__rt=fps&__ver=2

Its response body is quite massive, the information about multiple repositories is in:

fps -> dataProviders -> data -> ms.vss-build-web.run-details-data-provider -> repositoryResources.

Please check the link for the details. enter image description here

Upvotes: 1

GeralexGR
GeralexGR

Reputation: 3592

I am not sure if this will work, but I would try to cd into the repository directory for example $(Build.SourcesDirectory)/repo and then I would perform a powershell task

- task: PowerShell@2
  displayName: get git hash ID
  inputs:
    targetType: 'inline'
    script: |
      (git log --format="%H" -n 1).substring(0,8)

Upvotes: 0

Related Questions