Reputation: 41440
I have a pipeline that has
resources:
repositories:
In the GUI I can get the commit hash at the time the pipeline is run
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
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.
Upvotes: 1
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