Reputation: 16959
I am using the TFS2018 API to get all build definitions. I would like to know the last time a build definition was changed (also if build steps are changed).
To explain this better. I am using the API to batch update build definitions e.g. 100 build definition based on a template. If I change the template I will remove all the definition and create a new one based on the template. However if a specific build template is changed manually using the web admin page I don´t want to remove it because it has been customized.
I assume the revision is only created during a build. But there is a possibility that a user changes the build definition without building it.
Therefore I was hoping there would be a modified date whenever something is changed in a build definition?
UPDATE: I always get the same respone, an empty array, when calling the revision REST API "{\"count\":0,\"value\":[]}" "https://mytfsdomain/tfs/DefaultCollection/MyTeamProject/_apis/build/definitions/7332/revisions?api-version=2.0"
Even if I change the build definition 7332 I still get the same response. Any idea why there are no revisions?
Upvotes: 0
Views: 415
Reputation: 31093
api-version=4.1
is for VSTS. Since you are using TFS 2018, you need to use api-version=4.0
:
Get http://TFS2018:8080/tfs/DefaultCollection/TeamProject/_apis/build/definitions/{definitionId}/revisions?api-version=4.0
I also tried api-version=2.0
, it works as well. Check the screenshot below:
In addition, you could check the History tab when you edit the build definition, you could get changed date there too:
Upvotes: 1
Reputation: 1864
Yes, you need to query for the definition revisions. The JSON that gets returned contains the details of the changes. Depending on what you are using to parse the output, grab the last element of the value
array and then grab the changedDate
field. I also believe the value returned is UTC. Below is some PowerShell to help you out.
$pat = "[Your PAT]"
$vstsServiceCredentials = ":$pat"
$encodedVstsServiceCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($vstsServiceCredentials))
$authorizationHeader = @{ Authorization=("Basic {0}" -f
$encodedVstsServiceCredentials) }
$buildService = "https://[accountName].visualstudio.com/[projectName]/_apis/build/definitions/[BuildDefinitionId]/revisions?api-version=4.1"
$response = Invoke-RestMethod -Uri $buildService -Method Get -Headers
$authorizationHeader
Write-Host $response
Write-Host $response.value[$response.value.Length - 1].changedDate
Upvotes: 1
Reputation: 59045
This will require a few REST calls using the revisions API:
GET https://{url}/{project}/_apis/build/definitions/{definitionId}/revisions?api-version=4.1
The revision number is one of the optional parameters when retrieving a build definition, so you can retrieve a specific revision of the build definition and compare against the latest.
Upvotes: 1