Skip to content

Commit

Permalink
refactor: reuse variables from first stage rather than defining again
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Aug 29, 2023
1 parent d59fa1c commit 7efb502
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions experiment/experiment-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ stages:
# https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash#about-tasksetvariable
- bash: |
WORKSPACE=$(python experiment/experiment-workspace.py)
echo "##vso[task.setvariable variable=workspace]$WORKSPACE"
echo "##vso[task.setvariable variable=workspace;isOutput=true]$WORKSPACE"
TAG_TYPE=$(python experiment/tag.py)
echo "##vso[task.setvariable variable=tag_type]$TAG_TYPE"
echo "##vso[task.setvariable variable=tag_type;isOutput=true]$TAG_TYPE"
name: setvars
displayName: Determine deployment environment
env:
REASON: $(Build.Reason)
Expand Down Expand Up @@ -68,7 +69,7 @@ stages:
provider: azurerm
command: custom
customCommand: workspace
commandOptions: select $(workspace)
commandOptions: select $(setvars.workspace)
workingDirectory: "$(System.DefaultWorkingDirectory)/experiment"
# service connection
environmentServiceNameAzureRM: compiler-deployer
Expand Down Expand Up @@ -104,37 +105,24 @@ stages:
condition: succeeded()
environment: Approval
variables:
- name: OTHER_SOURCE
value: $[variables['System.PullRequest.SourceBranch']]
- name: INDIVIDUAL_SOURCE
value: $[variables['Build.SourceBranchName']]
- name: IS_TAG
value: $[startsWith(variables['Build.SourceBranch'], 'refs/tags/')]
- name: TARGET
value: $[variables['System.PullRequest.TargetBranch']]
- name: workspace
value: $[ stageDependencies.TerraformPlan.Plan.outputs['setvars.workspace'] ]
- name: tag_type
value: $[ stageDependencies.TerraformPlan.Plan.outputs['setvars.tag_type'] ]
strategy:
runOnce:
deploy:
steps:
- checkout: self
- bash: |
WORKSPACE=$(python experiment/experiment-workspace.py)
echo "##vso[task.setvariable variable=workspace]$WORKSPACE"
TAG_TYPE=$(python experiment/tag.py)
echo "##vso[task.setvariable variable=tag_type]$TAG_TYPE"
displayName: Determine tag type (either test or prod)
env:
REASON: $(Build.Reason)
# https://github.com/microsoft/azure-pipelines-terraform/tree/main/Tasks/TerraformTask/TerraformTaskV3#readme
- download: current
artifact: savedPlan
condition: |
or(
in(variables['Build.SourceBranchName'], 'dev'),
or(
eq(variables['tag_type'], 'test'),
eq(variables['tag_type'], 'prod')
eq($('tag_type'), 'test'),
eq($('tag_type'), 'prod')
)
)
- task: TerraformInstaller@0
Expand Down

0 comments on commit 7efb502

Please sign in to comment.