diff --git a/.pipelines/ci.yml b/.pipelines/ci.yml index 654181adcc4..5d6cacd572f 100644 --- a/.pipelines/ci.yml +++ b/.pipelines/ci.yml @@ -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 @@ -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: