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

Scriptrunner list of tags

Currently, I'm trying to configure "Scriptrunner for bitbucket server" to get a list of tags. Unfortunately, I did not found any solution for that task.
I also tried to find any reference manual for scriptrunner capabilities, but also failed.
Can anyone help me finding the solution?

1 answer

Hi @Mikita_Makarenka 

The documentation for ScriptRunner for Bitbucket can be found here:

I have also produced a Script for producing a report of the tags in your Bitbucket instance, which is based on a similar Script found in the docs ( and can be run in the Script Console.


import com.atlassian.bitbucket.project.ProjectService
import com.atlassian.bitbucket.repository.RefService
import com.atlassian.bitbucket.repository.Repository
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.bitbucket.repository.RepositoryTagsRequest
import com.atlassian.sal.api.component.ComponentLocator

import groovy.xml.MarkupBuilder

import static com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketCannedScriptUtils.unlimitedPager

def refService = ComponentLocator.getComponent(RefService)
def repositoryService = ComponentLocator.getComponent(RepositoryService)
def projectService = ComponentLocator.getComponent(ProjectService)

def allProjects = projectService.findAll(unlimitedPager).values
def tagsByProject = allProjects.collect { project ->

def repos = repositoryService.findByProjectKey(project.key, unlimitedPager).values
def repoTags = repos.collectEntries { Repository repo ->
[( refService.getTags(new RepositoryTagsRequest.Builder(repo).build(), unlimitedPager).values.collect { tag -> tag.displayId }]

project :,
repositories: repoTags

def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
builder.table(class: "aui") {
thead {
tr {
th("Project Name")
th("Repository Name")
tbody {
tagsByProject.each { dataRow ->
dataRow.repositories.eachWithIndex { Map.Entry repoRow, i ->
tr {
td {
if (i == 0) {
td {
table {
tbody {
repoRow.value.each { tag ->
tr {

return writer.toString()


Please let me know where you where you were planning to use this list of tags, so I can help further?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hello, Robert. Thank you for an answer. The idea was to block pull requests, whose target ref does not point to the commit with tag with name "release-*"
Currently, I've tried used your script to write mine (simplified version) and got these errors:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script518.groovy: 12: [Static type checking] - You tried to call a method which is not allowed: com.atlassian.bitbucket.repository.Ref#getLatestCommit()
 @ line 12, column 18.
   def targetHash = mergeRequest.pullRequest.toRef.latestCommit

Script518.groovy: 14: [Static type checking] - You tried to call a method which is not allowed: com.atlassian.bitbucket.repository.RepositoryTagsRequest$Builder#(com.atlassian.bitbucket.repository.Repository)
 @ line 14, column 42.
   gPresent = refService.getTags(new Reposi

Script518.groovy: 14: [Static type checking] - You tried to call a method which is not allowed: com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketCannedScriptUtils#getUnlimitedPager()
 @ line 14, column 91.
   equest.Builder(repo).build(), unlimitedP

Script518.groovy: 14: [Static type checking] - You tried to call a method which is not allowed: com.atlassian.bitbucket.repository.RefService#getTags(com.atlassian.bitbucket.repository.RepositoryTagsRequest,com.atlassian.bitbucket.util.PageRequest)
 @ line 14, column 23.
   def validTagPresent = refService.getTags(new RepositoryTagsRequest.Builder(repo).build(), unlimitedPager).values.any { tag ->

Script518.groovy: 15: [Static type checking] - You tried to call a method which is not allowed: com.atlassian.bitbucket.repository.Tag#getHash()
 @ line 15, column 57.
   th("/refs/tags/release-") &&  tag.hash =

5 errors

Can you explain how can I avoid them?

Hi @Никита Макаренко ,

There are some restrictions to the Bitbucket API when adding merge checks directly to a repository or project, as a repository admin or project admin.

Those API restrictions can cause those

You tried to call a method which is not allowed


In order to get around those errors, firstly please make sure you are using the latest version of ScriptRunner for Bitbucket as we allow more of the Bitbucket API to be used by project and repository admins, with newer releases of ScriptRunner.

And secondly, if the API is still not available by project or repository admins, a global Bitbucket administrator can add the merge check in the administration area of Bitbucket and then apply it to the projects and repositories you want it applied to.

I hope this helps answer your question?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Thank you, Robert. I've created a personal repository in Bitbucket and made a first commit there. After that I tried to create my merge check globally for that. The problem, I've met is that I can't see my project in the list view (where I'm supposed to choose the projects, which I wish to apply my merge check to). Can you comment that? Is there any indexation time gap for that list view?

Currently, I have no idea how to apply my merge check to my project, because it is not represented in the list of scriptrunner settings, though other projects are(a lot of them)

Hi @Никита Макаренко ,

Do you have over a 1000 projects in your Bitbucket instance?

If so, we are currently working on a fix to the project selection tree to allow for the display of more than a 1000 projects.

When that is released soon, I will update you.

Kind regards,

Robert Giddings,

ScriptRunner for Bitbucket

Ok, very luckily, this is the case. Thank you.

Sometime in the next few weeks @Никита Макаренко .

@Robert Giddings [Adaptavist] 
Hello, Robert
Is there any updates on that release?

Hi @Никита Макаренко ,

I believe it will be released around mid-December.

Kind regards,

Robert Giddings

Hi @Никита Макаренко ,

I am pleased to tell you that the new Project/Repo selection tree has now been released in version 6.16.0 of ScriptRunner for Bitbucket.

This new version of the tree should now support over a 1000 projects.

Kind regards,

Robert Giddings,

Project Manager, ScriptRunner for Bitbucket

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events