DevOpsHandling/Get-LastSuccessfulBuildId.ps1
function Get-LastSuccessfulBuildId { Param ( [Parameter(Mandatory=$true)] [string] $devOpsOrganization, [Parameter(Mandatory=$true)] [string] $devOpsProjectName, [Parameter(Mandatory=$true)] [string]$repositoryName, [Parameter(Mandatory=$true)] [string] $devOpsToken ) $build = (Invoke-AzureDevOpsApi -url ('https://dev.azure.com/{0}/{1}/_apis/build/builds/?repositoryId={2}&repositoryType=TfsGit&resultFilter=succeeded&queryOrder=finishTimeDescending&$top=1' -f $devOpsOrganization, $devOpsProjectName, (Get-RepositoryId -devOpsOrganization $devOpsOrganization -devOpsProjectName $devOpsProjectName -repositoryName $repositoryName -devOpsToken $devOpsToken)) -devOpsToken $devOpsToken).value try { return $build.id } catch { return "" } } Export-ModuleMember Get-LastSuccessfulBuildId |