Skip to content

Commit

Permalink
feat: set variable to indicate run is for a tag, update workspace logic
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Aug 17, 2023
1 parent e788837 commit e919339
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions terraform/pipeline/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ stages:
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']]
steps:
- bash: |
echo $(IS_TAG)
# set the workspace variable at runtime (rather than build time) so that all the necessary variables are available, and we can use Python
# https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash#about-tasksetvariable
- bash: |
Expand Down
4 changes: 4 additions & 0 deletions terraform/pipeline/workspace.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import re
import sys

REASON = os.environ["REASON"]
# the name of the variable that Azure Pipelines uses for the source branch depends on the type of run, so need to check both
SOURCE = os.environ.get("OTHER_SOURCE") or os.environ["INDIVIDUAL_SOURCE"]
TARGET = os.environ["TARGET"]
IS_TAG = os.environ["IS_TAG"]

# the branches that correspond to environments
ENV_BRANCHES = ["dev", "test", "prod"]
Expand All @@ -15,6 +17,8 @@
elif REASON in ["IndividualCI", "Manual"] and SOURCE in ENV_BRANCHES:
# it's being run on one of the environment branches, so use that
environment = SOURCE
elif REASON in ["IndividualCI"] and IS_TAG and re.fullmatch(r"20\d\d.\d\d.\d*", SOURCE):
environment = "test"
else:
# default to running against dev
environment = "dev"
Expand Down

0 comments on commit e919339

Please sign in to comment.