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.
I tried the following but get no build information...:
import com.atlassian.bitbucket.build.status.BuildStatusPullRequestSearchRequest
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.atlassian.bitbucket.build.BuildStatusService
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.atlassian.bitbucket.server.bitbucket-build")
import com.atlassian.bitbucket.build.status.BuildStatusRepositorySearchRequest
import com.atlassian.bitbucket.build.status.RepositoryBuildStatusService
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
@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 = repoBuildStatusService.search(
new BuildStatusRepositorySearchRequest.Builder(repo).build(),
new PageRequestImpl(0, 100)
).values
testsearch.each { build ->
log.warn "build="+build.toString()
}
}
}
Upper "testsearch" is empty, nothing to iterate...
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.