In my opinion, you are looking at this incorrectly.
Have you got a release pipeline to tie into your build as well ? This is crucial to ensure that you Git Delta Deploy is integrated correctly.
This is the Powershell script required to work out the last successful Git Commit ID for the Delta build to work, and it must be setup as a build step
param(
[string] $LastGitCommitId,
[string] $AccessToken,
[string] $AzureDevOpsAccountName,
[string] $TeamProjectId,
[string] $ReleaseDefinitionId
)
if ([string]::IsNullOrEmpty($LastGitCommitId))
{
$hdrs = @{}
$hdrs.Add("Authorization","Bearer $AccessToken")
try
{
$LatestSuccessfulRelease = Invoke-RestMethod -Method Get -Uri "https://$AzureDevOpsAccountName.vsrm.visualstudio.com/$TeamProjectId/_apis/release/releases?definitionId=$ReleaseDefinitionId&resultFilter=succeeded&`$top=1" -ContentType 'application/json' -Headers $hdrs
if ($LatestSuccessfulRelease.count -eq 1)
{
$ReleaseDetailUrl = $LatestSuccessfulRelease.value[0].url
try
{
$ReleaseArtifactDetail = Invoke-RestMethod -Method Get -Uri "$ReleaseDetailUrl" -ContentType 'application/json' -Headers $hdrs
if ($ReleaseArtifactDetail.PSobject.Properties.name -notcontains "innerException")
{
$artifacts = $ReleaseArtifactDetail.artifacts | where {$_.definitionReference.project.id -eq $TeamProjectId}
if ($artifacts -ne $null)
{
$GitCommitId = $artifacts[0].definitionReference.pullRequestMergeCommitId.id
Write-Host "##vso[task.setvariable variable=LastGitCommitId;]$GitCommitId"
}
}
else
{
Write-Host "##vso[task.complete result=Failed;]Error in getting Release Details"
}
}
catch
{
Write-Host "##vso[task.complete result=Failed;]Error in getting Release Details"
}
}
else
{
Write-Host "##vso[task.complete result=Failed;]Error in getting the latest successful release."
}
}
catch
{
Write-Host "##vso[task.complete result=Failed;]Error in getting the latest successful release."
}
}
The MSBuild properties that needs to be overridden during builds will need to look like this:
/property:LastDeploymentGitCommitID=%env.LastSuccessfulRunGitCommitId% /property:LastDeploymentGitTagName=
My blog post has a lot more details on how to get this all working.
https://medium.com/@Vincent_Lui/yet-another-hedgehog-team-development-for-sitecore-setup-from-developer-workstation-to-ci-cd-98ec4fc1161b