Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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
4,552,516
Community Members
 
Community Events
184
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

0 votes
Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 13, 2020

Hi @Mikita_Makarenka 

The documentation for ScriptRunner for Bitbucket can be found here: https://scriptrunner.adaptavist.com/latest/bitbucket/quickstart.html

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 (https://scriptrunner.adaptavist.com/latest/bitbucket/ScriptConsole.html#_list_all_repository_sizes_by_project) 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 ->
[(repo.name): refService.getTags(new RepositoryTagsRequest.Builder(repo).build(), unlimitedPager).values.collect { tag -> tag.displayId }]
}

[
project : project.name,
repositories: repoTags
]
}

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

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?

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 03, 2020

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

errors.

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)

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 05, 2020

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.

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 12, 2020

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

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

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 27, 2020

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

I believe it will be released around mid-December.

Kind regards,

Robert Giddings

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 18, 2020

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
TAGS
AUG Leaders

Atlassian Community Events