Created
March 29, 2024 16:24
-
-
Save kevball2/a162070ca51d7a69f6ba5693a949bd31 to your computer and use it in GitHub Desktop.
Azdo conditional check for changes to IaC files
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
#determines if changes were made to the IaC files since the last commit | |
- stage: verify_changes | |
displayName: "Determine updated files" | |
jobs: | |
- job: determine_changes_infra | |
displayName: Determine if infrastructure code has been updated. | |
steps: | |
- powershell: | | |
$changedFiles = git diff HEAD HEAD~ --name-only | |
git diff HEAD HEAD~ --name-only | |
$matchesIaC = Select-String -InputObject $changedFiles -Pattern "templates/IaC" -AllMatches | |
$updatedIaC = $matchesIaC.Matches.Count -gt 0 | |
write-host "Infra files updated: $updatedIaC" | |
Write-host "##vso[task.setvariable variable=updatedIaC;isOutput=true;]$updatedIaC" | |
name: infra_changed | |
#stage gets the updatedIaC value and uses it to evaluate if the Iac Jobs should run | |
- stage: deploy_${{ environmentObject.environmentName }}_stage | |
dependsOn: | |
- verify_changes | |
condition: and(eq(variables.shouldExecuteJob, 'True'),succeeded()) | |
variables: | |
- name: shouldExecuteJob | |
value: $[ stageDependencies.verify_changes.determine_changes_infra.outputs['infra_changed.updatedIaC'] ] | |
# conditional check on the deployment job | |
- deployment: infra_deploy_${{ environmentObject.environmentName }} | |
continueOnError: false | |
environment: ${{ environmentObject.environmentName }} | |
timeoutInMinutes: 120 | |
condition: eq(variables.shouldExecuteJob, 'True') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment