diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 0b5c7a7..cee2945 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -212,13 +212,16 @@ pipelines: image: atlassian/default-image:4 script: - | + # Resolve source branch (fallback to BITBUCKET_BRANCH if PR variable unavailable) + SOURCE_BRANCH="${BITBUCKET_PR_SOURCE_BRANCH:-$BITBUCKET_BRANCH}" + TARGET_BRANCH="${BITBUCKET_PR_DESTINATION_BRANCH}" # Gate: feature branches can only target dev ALLOWED="dev" - echo "Source: ${BITBUCKET_PR_SOURCE_BRANCH}" - echo "Target: ${BITBUCKET_PR_DESTINATION_BRANCH} (allowed: ${ALLOWED})" + echo "Source: ${SOURCE_BRANCH}" + echo "Target: ${TARGET_BRANCH} (allowed: ${ALLOWED})" IFS=',' read -ra targets <<< "$ALLOWED" for t in "${targets[@]}"; do - [ "${BITBUCKET_PR_DESTINATION_BRANCH}" = "$t" ] && exit 0 + [ "${TARGET_BRANCH}" = "$t" ] && exit 0 done echo "BLOCKED: target must be one of: ${ALLOWED}"; exit 1 - step: *ai-code-review @@ -236,13 +239,16 @@ pipelines: image: atlassian/default-image:4 script: - | + # Resolve source branch (fallback to BITBUCKET_BRANCH if PR variable unavailable) + SOURCE_BRANCH="${BITBUCKET_PR_SOURCE_BRANCH:-$BITBUCKET_BRANCH}" + TARGET_BRANCH="${BITBUCKET_PR_DESTINATION_BRANCH}" # Gate: bugfix branches can only target dev ALLOWED="dev" - echo "Source: ${BITBUCKET_PR_SOURCE_BRANCH}" - echo "Target: ${BITBUCKET_PR_DESTINATION_BRANCH} (allowed: ${ALLOWED})" + echo "Source: ${SOURCE_BRANCH}" + echo "Target: ${TARGET_BRANCH} (allowed: ${ALLOWED})" IFS=',' read -ra targets <<< "$ALLOWED" for t in "${targets[@]}"; do - [ "${BITBUCKET_PR_DESTINATION_BRANCH}" = "$t" ] && exit 0 + [ "${TARGET_BRANCH}" = "$t" ] && exit 0 done echo "BLOCKED: target must be one of: ${ALLOWED}"; exit 1 - step: *ai-code-review @@ -261,13 +267,16 @@ pipelines: image: atlassian/default-image:4 script: - | + # Resolve source branch (fallback to BITBUCKET_BRANCH if PR variable unavailable) + SOURCE_BRANCH="${BITBUCKET_PR_SOURCE_BRANCH:-$BITBUCKET_BRANCH}" + TARGET_BRANCH="${BITBUCKET_PR_DESTINATION_BRANCH}" # Gate: hotfix branches can target main (fast-track) or dev ALLOWED="main,dev" - echo "Source: ${BITBUCKET_PR_SOURCE_BRANCH}" - echo "Target: ${BITBUCKET_PR_DESTINATION_BRANCH} (allowed: ${ALLOWED})" + echo "Source: ${SOURCE_BRANCH}" + echo "Target: ${TARGET_BRANCH} (allowed: ${ALLOWED})" IFS=',' read -ra targets <<< "$ALLOWED" for t in "${targets[@]}"; do - [ "${BITBUCKET_PR_DESTINATION_BRANCH}" = "$t" ] && exit 0 + [ "${TARGET_BRANCH}" = "$t" ] && exit 0 done echo "BLOCKED: target must be one of: ${ALLOWED}"; exit 1 - step: *ai-code-review @@ -286,13 +295,16 @@ pipelines: image: atlassian/default-image:4 script: - | + # Resolve source branch (fallback to BITBUCKET_BRANCH if PR variable unavailable) + SOURCE_BRANCH="${BITBUCKET_PR_SOURCE_BRANCH:-$BITBUCKET_BRANCH}" + TARGET_BRANCH="${BITBUCKET_PR_DESTINATION_BRANCH}" # Gate: dev can only be promoted to stg ALLOWED="stg" - echo "Source: ${BITBUCKET_PR_SOURCE_BRANCH}" - echo "Target: ${BITBUCKET_PR_DESTINATION_BRANCH} (allowed: ${ALLOWED})" + echo "Source: ${SOURCE_BRANCH}" + echo "Target: ${TARGET_BRANCH} (allowed: ${ALLOWED})" IFS=',' read -ra targets <<< "$ALLOWED" for t in "${targets[@]}"; do - [ "${BITBUCKET_PR_DESTINATION_BRANCH}" = "$t" ] && exit 0 + [ "${TARGET_BRANCH}" = "$t" ] && exit 0 done echo "BLOCKED: target must be one of: ${ALLOWED}"; exit 1 - step: *ai-code-review @@ -311,17 +323,20 @@ pipelines: image: atlassian/default-image:4 script: - | + # Resolve source branch (fallback to BITBUCKET_BRANCH if PR variable unavailable) + SOURCE_BRANCH="${BITBUCKET_PR_SOURCE_BRANCH:-$BITBUCKET_BRANCH}" + TARGET_BRANCH="${BITBUCKET_PR_DESTINATION_BRANCH}" # Gate: stg can only be promoted to main ALLOWED="main" - echo "Source: ${BITBUCKET_PR_SOURCE_BRANCH}" - echo "Target: ${BITBUCKET_PR_DESTINATION_BRANCH} (allowed: ${ALLOWED})" + echo "Source: ${SOURCE_BRANCH}" + echo "Target: ${TARGET_BRANCH} (allowed: ${ALLOWED})" IFS=',' read -ra targets <<< "$ALLOWED" for t in "${targets[@]}"; do - [ "${BITBUCKET_PR_DESTINATION_BRANCH}" = "$t" ] && exit 0 + [ "${TARGET_BRANCH}" = "$t" ] && exit 0 done echo "BLOCKED: target must be one of: ${ALLOWED}"; exit 1 - step: *ai-code-review - + # ------------------------------------------------------------------------- # Catch-all: Enforce branch naming standards # ------------------------------------------------------------------------- @@ -342,10 +357,12 @@ pipelines: image: atlassian/default-image:4 script: - | + # Resolve source branch (fallback to BITBUCKET_BRANCH if PR variable unavailable) + SOURCE_BRANCH="${BITBUCKET_PR_SOURCE_BRANCH:-$BITBUCKET_BRANCH}" echo "============================================================" echo "BRANCH NAMING STANDARD VIOLATION" echo "============================================================" - echo "Branch: ${BITBUCKET_PR_SOURCE_BRANCH}" + echo "Branch: ${SOURCE_BRANCH}" echo "" echo "This branch does not match allowed naming conventions." echo ""