I am building a CI/CD pipeline with the following steps:
- Check for any changes.
- If changes are found, deploy.
This setup is intended for multiple environments. However, I am encountering an issue when there are more than one environment to deploy:
The deployment for the first environment from the template works as expected. However, the second environment, despite detecting changes, does not initiate the deployment and is marked as “skipped”. First env always work like a charm:
Here’s a simplified version of my pipeline configuration:
trigger:
batch: true
branches:
include:
- main
pr:
branches:
include:
- main
stages:
- template: templates/deploy.yml
parameters:
environment: Dev
- template: templates/deploy.yml
parameters:
environment: Uat
and deploy.yml
template:
stages:
- stage: Terraform_Plan_${{ parameters.environment }}
displayName: Plan
condition: always()
jobs:
- job: Terraform_Plan_${{ parameters.environment }}
displayName: Plan Terraform
pool: 'selfhosted'
steps:
- powershell: |
# set it to true or false
Write-Host "##vso[task.setvariable variable=anyTfChanges;isOutput=true]true"
displayName: Detect any Terraform changes
name: anyTfChanges
- stage: Any_Tf_Changes_${{ parameters.environment }}
displayName: Terraform Changes
dependsOn: Terraform_Plan_${{ parameters.environment }}
variables:
anyTfChanges: $[ stageDependencies.Terraform_Plan_${{ parameters.environment }}.Terraform_Plan_${{ parameters.environment }}.outputs['anyTfChanges.anyTfChanges'] ]
condition: and(eq('true', 'true'), eq(dependencies.Terraform_Plan_${{ parameters.environment }}.outputs['Terraform_Plan_${{ parameters.environment }}.anyTfChanges.anyTfChanges'], 'true'))
jobs:
- job: Terraform_Changes_${{ parameters.environment }}
displayName: Detect Terraform Changes
steps:
- checkout: none
- powershell: |
Write-Host "hello world"
displayName: Terraform changes detected
- stage: Terraform_Apply_${{ parameters.environment }}
displayName: Apply ${{ parameters.environmentDisplayName }}
dependsOn: Any_Tf_Changes_${{ parameters.environment }}
jobs:
- deployment: Apply
environment: ${{ parameters.environmentDisplayName }}
displayName: Apply Terraform
pool: 'selfhosted'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- script: |
Write-Host "hello world"
Could I be overlooking something in my configuration that causes the pipeline to behave this way for subsequent environments? Any insights or suggestions would be appreciated!