The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script runner bitbucket package and api

Vava
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 7, 2024

I’m trying to solve a problem where in.

Fetch the latest commit from the pull request and the develop branch. Compare the time the build of both by getting the build information of the latest commit on both. If the time of the build on develop is ahead of the pull request then veto “ there’s a commit in development branch, please trigger a new build manually”

This will block the pull request from getting merged without triggering a new build.

 

This is a custom merge check script for 7.x. I’m unable to find a similar package of buildservice which is deprecated in 8.X.

import com.atlassian.sal.api.component.ComponentLocator import com.atlassian.bitbucket.build.BuildService import com.atlassian.bitbucket.build.BuildState

def buildService = ComponentLocator.getComponent(BuildService)

def repository = repository

def pullRequest = pullRequest

def prBuilds = buildService.getBuilds(repository, pullRequest.getFromRef).getLatestCommit())

def developBuilds = buildService.getBuilds(repository, "develop")

def prLatestBuildTime = prBuilds.getValues).max { it.dateStarted.time }

def developLatestBuild Time = developBuilds.getValues).max { it .dateStarted.time }

if (developLatestBuild Time > prLatestBuild Time) {

veto ("Develop build is newer, merge blocked. Please trigger a new build manually”)

}

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events