Bitbucket Scriptrunner Posthook - Get Build Information

Roth_ Thomas June 14, 2023

Hi together,

I use Bitbucket Scriptrunner to trigger a script via PostHook. This Script sends a webhook to another system. I want to send information about the build status in this webhook, but I can't get the build information via groovy script.

2023-06-14 10_09_44-Builds für DB_ Broker _ micro-case-assignment-service-prod - Bitbucket.png

I tried the following but get no build information...:


import com.atlassian.bitbucket.hook.repository.PullRequestMergeHookRequest
import com.atlassian.bitbucket.pull.PullRequest
import com.atlassian.bitbucket.project.Project
import com.atlassian.bitbucket.repository.Repository
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.bitbucket.util.*
import com.atlassian.bitbucket.repository.RefChange
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.bitbucket.util.PageRequestImpl
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.runner.customisers.PluginModule
RepositoryBuildStatusService repositoryBuildStatusService

def applicableEvent;
PullRequest pullRequest;
Repository repo;
Project project;
applicableEvent         = hookRequest;
if (applicableEvent instanceof PullRequestMergeHookRequest) {
pullRequest         = applicableEvent.getPullRequest();
repo                = repository;
project             = repo.project;

def repoBuildStatusService = ScriptRunnerImpl.getOsgiService(RepositoryBuildStatusService)
log.warn "repoBuildStatusService="+repoBuildStatusService
def testsearch
if(repoBuildStatusService != null){
testsearch =
  new BuildStatusRepositorySearchRequest.Builder(repo).build(),
  new PageRequestImpl(0, 100)
testsearch.each { build ->
    log.warn "build="+build.toString()

Upper "testsearch" is empty, nothing to iterate...

I hope someone can help, thank you!

1 answer

1 accepted

1 vote
Answer accepted
Roth_ Thomas June 19, 2023

I contacted atlassian support and got the right hint in minutes. I responded to the pull request merged event. At this time the builds were not finished. I worked with a while-loop and sleep statements and now it works.

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events