Skip to content

Commit

Permalink
Fix TAG assignment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhadapaithankar committed Dec 6, 2024
1 parent d268a53 commit d587be9
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions .pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ variables:
value: arosvcdev.azurecr.io/e2e
- name: VERSION
value: $(TAG)
- name: MASTER_TAG
value: $[ format('master-{0}', variables['Build.SourceVersion']) ]
- name: TAG
value: ''
- name: ARO_IMAGE
value: arosvcdev.azurecr.io/aro:$(TAG)
- name: ARO_SELENIUM_HOSTNAME
Expand All @@ -39,37 +35,39 @@ variables:
value: "!smoke&&!regressiontest"

stages:
- stage: SetVariables
displayName: Set TAG and PR_TAG Dynamically
- stage: Calculate_Tag
displayName: Calculate and Sanitize Tag for Build
jobs:
- job: SetVariablesJob
- job: CalculateTag
displayName: Generate and Sanitize TAG Variable
pool:
vmImage: 'ubuntu-latest'
steps:
# Dynamically set PR_TAG if this is a PR build
# Calculate and sanitize TAG
- script: |
if [ -n "$SYSTEM_PULLREQUEST_PULLREQUESTID" ]; then
echo "##vso[task.setvariable variable=PR_TAG;isOutput=true]pr-$SYSTEM_PULLREQUEST_PULLREQUESTID-$SYSTEM_PULLREQUEST_SOURCECOMMITID"
# Check if this is a PR build or master build
if [ -n "$(System.PullRequest.PullRequestId)" ] && [ "$(System.PullRequest.PullRequestId)" != "null" ]; then
RAW_TAG="pr-$(System.PullRequest.PullRequestId)-$(System.PullRequest.SourceCommitId)"
else
echo "##vso[task.setvariable variable=PR_TAG;isOutput=true]''"
RAW_TAG="master-$(Build.SourceVersion)"
fi
displayName: Set PR_TAG for Pull Request Builds
# Set TAG dynamically based on PR_TAG or MASTER_TAG
- script: |
if [ -n "$(PR_TAG)" ]; then
echo "##vso[task.setvariable variable=TAG;isOutput=true]$(PR_TAG)"
else
echo "##vso[task.setvariable variable=TAG;isOutput=true]$(MASTER_TAG)"
fi
displayName: Set TAG Based on PR_TAG or MASTER_TAG
# Sanitize TAG by replacing invalid characters and truncating
TAG=$(echo "$RAW_TAG" | sed 's/[^a-zA-Z0-9._-]/-/g' | cut -c1-63)
variables:
PR_TAG: $[ dependencies.SetVariables.outputs['SetVariablesJob.PR_TAG'] ]
TAG: $[ dependencies.SetVariables.outputs['SetVariablesJob.TAG'] ]
# Set TAG as a pipeline variable
echo "##vso[task.setvariable variable=TAG]$TAG"
echo "Computed and Sanitized TAG: $TAG"
displayName: Calculate and Sanitize TAG Variable
# Debug TAG to ensure correctness
- script: |
echo "Debugging TAG value..."
echo "TAG: $(TAG)"
displayName: Debug TAG Variable
- stage: Containerized_CI
dependsOn: SetVariables
jobs:
- job: Build_Test_And_Push_Az_ARO_Extension
pool:
Expand Down

0 comments on commit d587be9

Please sign in to comment.