The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to run a pipeline script on only the updated files in the pull request?

Joseph Thayne
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 12, 2020

I have a PHP project that i am wanting to add CodeSniffer (phpcs) to via a pipeline. I currently have it running unit tests, so I am not worried about getting it working generally. I will have no issues being able to run the code sniffer over all files. However, there are will over 1000 files in the project, so it will take a while to run. I would love to be able to run the sniffer only over those files that were changed in the pull request. Is there a way to do that? I can't seem to locate any information on this.

I have these two git commands that should give me what I am looking for, but haven't determined which is more consistent:

git diff --name-only HEAD...master

and

git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD master)

Any help on how to get that information inside a pipeline would be greatly appreciated. Thank you.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
mkleint
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 2, 2020

You might want to check this bitbucket API that should return you the files changed in the pullrequest

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/diffstat

 

in PR triggered builds you get the pull request's ID as environment variable - BITBUCKET_PR_ID (https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html)

TAGS
AUG Leaders

Atlassian Community Events