'Bitbucket pipeline for merge commit only

I have this git command at Bitbucket pipeline script which will generate list of changed files with path.

export FILES=$(git diff-tree --no-commit-id --name-only -r HEAD^^..HEAD)

problem is that it will generate on all commint. How to get list files only merge commit to master? Or how to say in pipelipe script to run on merge event only?

After some experiments I extended my script like this:

image: python:3.5.7

pipelines:
  branches:
    master:
      - step:
          script:
            - apt-get update
            - apt-get -qq install zip curl
            - mkdir $BITBUCKET_REPO_SLUG

            - export VERSION_LABEL=$(date +%Y-%m-%d_%H:%M:%S)
            - export ZIP_FILE=package_$BITBUCKET_REPO_SLUG_$VERSION_LABEL.zip
            - export FILES=$(git diff-tree --no-commit-id --name-only -r HEAD^^..HEAD)

            - echo "Repo name is $BITBUCKET_REPO_SLUG & version is $VERSION_LABEL"

            - cp -R --parents $FILES $BITBUCKET_REPO_SLUG/ 2>/dev/null

            - rm -f $BITBUCKET_REPO_SLUG/bitbucket-pipelines.yml
            - rm -f $BITBUCKET_REPO_SLUG/.gitignore

            - zip -r $ZIP_FILE $BITBUCKET_REPO_SLUG/

And now it is executed when I make merge into master but it do nothing and raw report is:

+ cp -R --parents $FILES $BITBUCKET_REPO_SLUG/ 2>/dev/null
Searching for test report files in directories named [test-results, failsafe-reports, test-reports, TestResults, surefire-reports] down to a depth of 4
Finished scanning for test reports. Found 0 test report files.
Merged test suites, total number tests is 0, with 0 failures and 0 errors.

Do I need change

HEAD^^..HEAD

into other parameter?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source