1

I would like to control what happens in bitbucket pipelines based on which files have changed when a pull request is approved and merged into destination branch. The problem I am running into is that bitbucket commits prior to running the pipeline. So when the pipeline is kicked off, all commits are on the current branch. So I don't understand how can I know which files have changes since the last time a pipeline was run?

I don't think git show HEAD^1 would work because there might be dozens of commits. I don't know how to do git diff between the latest commit PRIOR to merging the pull request vs latest commit that was just merged as part of the pull request.

Is there a way to know which files are changing as part of the pull request using git commands? Essentially, same information that Bitbucket shows you when you are reviewing a pull request, how can I get that list of files?

kravb
  • 417
  • 4
  • 16
  • Check [my answer](https://stackoverflow.com/a/63486449/1119153) over [this question](https://stackoverflow.com/questions/49652286/run-pipeline-only-on-changes-in-one-dir) – manasouza Aug 27 '20 at 10:45
  • @manasouza I have seen the changesets option. Do you know if changesets can be used twice in the same step? Since you can't reuse the same environment between steps, we would need two changesets to be evaluated in the same step. – kravb Aug 28 '20 at 14:27

1 Answers1

1

Found a solution using bitbucket API using endpoint (documented here)

Using the bitbucket commit, you can make a GET call to this endpoint: https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/diffstat/{commit}

When running this command during a bitbucket pipeline, all three variables are available with bitbucket default variables (listed here)

Using python requests library, make a get request per usual:

headers = {'Content-Type': 'application/json'}
r = requests.get(url, auth=(<username>,<app_password>), headers=headers)

Bitbucket no longer accepts passwords so you have to create an app password to use in place of your account password (instructions here)

When doing a GET against this endpoint with a valid commit ( only tried with short version not full length SHA), I receive a json which contains a list of dictionaries for each change.

kravb
  • 417
  • 4
  • 16