2. The use clicks on the "Merge" button
3. The merge occurs and the bitbucket-pipeline gets exectued
4. the bitbucket-pipeline code tries to detect if this particular build got called because of merge.
image: docker/compose:latest # Docker image with Docker Compose pre-installed
pipelines:
default:
- step:
name: Detect Merge Commit
image: atlassian/default-image:3 # Switch to an image with Git pre-installed
script:
- |
if [ -n "$BITBUCKET_PR_ID" ]; then
echo "This build was triggered by a pull request. PR ID: $BITBUCKET_PR_ID"
else
echo "This build was not triggered by a pull request."
fi
- git rev-parse HEAD # Output the current commit hash
- echo "Checking if the current commit is a merge commit..."
- git rev-list --parents -n 1 HEAD
- |
# Get the parent commits of the current commit
PARENTS=$(git rev-list --parents -n 1 HEAD)
# Count the number of parents
NUM_PARENTS=$(echo $PARENTS | wc -w)
# Check if there is more than one parent
if [ $NUM_PARENTS -le 2 ]; then
echo "Not a merge commit. Exiting..."
exit 0 # Exit the step if it's not a merge commit
fi
# If it's a merge commit, the following scripts will run
echo "Merge commit detected! Running merge-specific steps..."
echo "Deploying to staging environment..."
- |