I'm trying to check the build status of the last commit in a pull request but can't get the BuildStatusService to get resolved using ComponentLocator.getComponent(BuildStatusService). It always returns null.
This is my script which runs as Merge Check script.
@BaseScript BitbucketBaseScript baseScript
def commitId = mergeRequest.pullRequest.fromRef.latestCommit
def buildStatusService = ComponentLocator.getComponent(BuildStatusService)
String debugMessage = "commitId=" + commitId + ", buildStatusService=" + buildStatusService
mergeRequest.veto("Pull request can't be merged", "Pull request can't be merged: " + debugMessage)
I copied the basic code from this link, but the result that I'm getting on the pull request 'Merge' button is:
Pull request can't be merged: commitId=c933d15fd5222d5d79e16b58c76de2a5874c6173, buildStatusService=null
I'm running on Atlassian Bitbucket Server v4.8.3. Any ideas why this does not work?
You should be able to get the BuildStatusService by using:
def buildStatusService = ScriptRunnerImpl.getOsgiService(BuildStatusService)
As it's listed as an OSGI service in the bitbucket-build plugin you need to use @WithPlugin and ScriptRunnerImpl.getOsgiService
Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda ...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
We're bringing product updates and pro tips on teamwork to ten cities around the world.Save your spot