Last active
August 10, 2021 03:04
-
-
Save SQLDBAWithABeard/d5f69ad50f793630d09f3d547cd95a82 to your computer and use it in GitHub Desktop.
azure repo which files have changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: AzurePowerShell@5 | |
displayName: Deploy Changes | |
inputs: | |
azureSubscription: '' | |
ScriptType: 'InlineScript' | |
Inline: | | |
# Get the changes for the current build | |
$webClient = New-Object Net.WebClient | |
$token = "Bearer $env:SYSTEM_ACCESSTOKEN" | |
$headers = @{ Authorization = $token } | |
$devOpsUrl = "$(System.TeamFoundationCollectionUri)" | |
$projectName = "$(System.TeamProject)" | |
$repoId = "$(Build.Repository.Id)" | |
$repoName = "$(Build.Repository.Name)" | |
$BuildId = "$(Build.buildID)" | |
$request = "$devOpsUrl$projectName/_apis/build/builds/$BuildID/changes" | |
$response = Invoke-WebRequest -Uri $request -Headers $headers | |
$json = ($response.Content | ConvertFrom-Json) | |
# Get the earliest Commit | |
$EarliestCommitID = ($json.Value |Sort-Object timestamp | Select-Object -First 1).id | |
$LatestCommitID = ($json.Value |Sort-Object timestamp -Descending| Select-Object -First 1).id | |
$fileschanged = git diff-tree --dirstat=files,0 --no-commit-id --name-only -r $EarliestCommitID^ $LatestCommitID | |
$deployscriptchanged = $fileschanged.Where{($_ -like '*ResourceGroups*') -and (($_ -like '*deploy.ps1') -or ($_ -like '*deploy.params.json'))} | |
$Message = "These are the files that have changed - {0}" -f ($fileschanged -join ' '|Out-String) | |
Write-Host "##[section] $Message" | |
# Do the magic thinngs here | |
azurePowerShellVersion: 'LatestVersion' | |
env: | |
SYSTEM_ACCESSTOKEN: $(system.accesstoken) | |
pwsh: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment