Skip to content

Commit

Permalink
chore(pipeline): select workspace in python
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld committed Nov 4, 2022
1 parent d094888 commit d596df2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
15 changes: 11 additions & 4 deletions terraform/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ stages:
vmImage: ubuntu-latest
jobs:
- job: plan
# https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#conditional-insertion
variables:
reason: $[variables['Build.Reason']]
target: $[variables['System.PullRequest.TargetBranch']]
steps:
- bash: |
echo $REASON
echo $SOURCE
echo $TARGET

WORKSPACE=$(python terraform/workspace.py)
echo "##vso[task.setvariable variable=one]$(WORKSPACE)"
env:
REASON: $(Build.Reason)
SOURCE: $(Build.SourceBranchName)
TARGET: $(System.PullRequest.TargetBranch)
- task: Bash@3
inputs:
targetType: "inline"
Expand Down
13 changes: 13 additions & 0 deletions terraform/workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

REASON = os.environ["REASON"]
SOURCE = os.environ["SOURCE"]
TARGET = os.environ["TARGET"]

# on pull requests, base on target branch; otherwise base on the source branch
if REASON == "PullRequest" and TARGET in ["test", "prod"]:
print(TARGET)
elif SOURCE in ["test", "prod"]:
print(SOURCE)
else:
print("dev")

0 comments on commit d596df2

Please sign in to comment.