Search code examples
bitbucketbitbucket-pipelinesbitbucket-cloud

bitbucket pipeline - InBuilt variable prints empty value


I am trying to implement python static analysis for one of my project. However, I want to do this only on difference of file rather than all the files. The reason being we have lots of file already committed which has issue and it's not feasible to fix it in time.

I am trying to use following code, but it's failing.

pipelines:
  default:
       - step:
          name: python_static_analysis
          image: python:3.7.3
          script:
            - pip install flake8
            - echo $BITBUCKET_BRANCH
            - echo $BITBUCKET_PR_DESTINATION_BRANCH
            - git diff -u -relative origin/$BITBUCKET_BRANCH origin/$BITBUCKET_PR_DESTINATION_BRANCH --name-only -- '*.py'
            #- flake8 $(git diff -u -relative origin/$BITBUCKET_BRANCH origin/$BITBUCKET_PR_DESTINATION_BRANCH --name-only -- '*.py')

this is the errror

enter image description here

BITBUCKET_PR_DESTINATION_BRANCH variable comes out as empty, not sure why ?


Solution

  • As the documentations says https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/#Default-variables the BITBUCKET_PR_DESTINATION_BRANCH variable is

    Only available on a pull request triggered build.

    So the problem is that you defined this step as part of a default pipeline whereas you should have written

    pipelines:
      pull-requests:
        '**':
          - step:
              # ...