Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Bitbucket - get commited file content


Is there a way to have a conditional merge check script which would check if variable X defined in the committed file is equal to its counterpart variable X' in the master file. 

1 answer

1 accepted


I'm Reece, an engineer working on ScriptRunner for Bitbucket.

It should be possible for you to achieve what you describe by comparing the content of the file on the source branch vs the target branch (master in your case).

Here is some example code that you could use in a conditional merge check to do this:

import com.atlassian.bitbucket.content.ContentService
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.hook.repository.PullRequestMergeHookRequest

def contentService = ComponentLocator.getComponent(ContentService)
def pullRequest = (hookRequest as PullRequestMergeHookRequest).pullRequest

def file = ""

def sourceBranchFileStream = new ByteArrayOutputStream()
contentService.streamFile(repository,, file, { sourceBranchFileStream })

def targetBranchFileStream = new ByteArrayOutputStream()
contentService.streamFile(repository,, file, { targetBranchFileStream })

def sourceBranchProperties = new Properties()
sourceBranchProperties.load(new ByteArrayInputStream(sourceBranchFileStream.toByteArray()))

def targetBranchProperties = new Properties()
targetBranchProperties.load(new ByteArrayInputStream(targetBranchFileStream.toByteArray()))

def nonMatchingProperty = sourceBranchProperties.findResult {
if (targetBranchProperties.get(it.key) != it.value) {
return it


if (nonMatchingProperty) {
return true



The above snippet takes the content of the file from the source branch, and compares it to the contents of the target branch, this is done by constructing a Properties instance and then comparing the entries.

The above snippet can only be configured by a global administrator, as it uses ContentService and this is not available in hooks configured at the repository level by a repository administrator.

If you have any further questions please let me know.

Kind regards,


Hello Reece

Thx for the quick response! Actually, I have a difficulty testing your solution since I do not have global administrator rights... Is there any workaround for mere mortals repo admins? :) 

Maybe to add some details - we want to have automatic version incrementation in a file on merge.  E.g. version = 5.3.11 -> version = 5.3.12. In some ideal world we would also like to label 5.3.12 to the related jira afterwords, but this...

Thx in advance for help!

Hello again,

Unfortunately there is not a workaround, ContentService is not permitted for usage by repository administrators as it can be used to access content in files from multiple repositories. To allow its usage, we would need to thoroughly check that the API is safe for a repository administrator to use.

It is possible we could add something to the product to facilitate this use case in a secure manner, I'd be happy to add an item to our backlog for that.

Kind regards,


We have an existing feature request for the above:

If you could leave a vote/comment on the above ticket, that would help when the team comes to prioritise this :)

Hello Reece

Ok, I see... 

Just the last question - what it the best documentation source for adaptavist scripts? Cause looks really messy (sorry :( ) 


The main documentation for the product is the link you refer to, we are currently working on updating the documentation with additional content and reworking the existing content onto a new platform, if there is anything you can't find an answer for please let me know and I can point you in the correct direction.

In addition to the product documentation, we also have the Adaptavist Library, which is a collection of code examples for various use cases, at the moment we only have a couple of examples for Bitbucket specifically, but we are working on adding more of these in the near future: Adaptavist Library 

You can also reach out to our customer support team who should be able to provide some guidance, they cannot write custom code for you, but they can provide tips and link you to relevant API documentation etc.

Kind regards,


Suggest an answer

Log in or Sign up to answer

Atlassian Community Events