How to prevent merge at certain times of the week

DanielTian June 7, 2022

Hi, I tried to use Conditional merge check to prevent merge  after 1 PM on Tuesday but I failed. I wrote the codes below in ScriptRunner and I got a lot of Static type checking errors like "Script15.groovy: 1: [Static type checking] - You tried to call a method which is not allowed: java.util.Calendar#getInstance()".

def cal = Calendar.instance
TimeZone tz = TimeZone.getTimeZone("Asia/Tokyo");
cal.setTimeZone(tz);
def hour = cal.get(Calendar.HOUR_OF_DAY)
Calendar.TUESDAY == cal.get(Calendar.DAY_OF_WEEK)&&hour >= 13

It seems that Calendar can't be used here and I want to know is there any other way to prevent merge at certain times of the week?

1 answer

Hi @DanielTian 

Did you try to create this merge check from the project or repository settings screens, instead of the global bitbucket admin screen? You should use the second option as the other screens are accessible to non-admins, and are executed in a more restricted sandbox.

You could log in as an admin, go to the merge checks through the Scriptrunner admin screen (under ../plugins/servlet/scriptrunner/admin/mergechecks), and create a new 'Conditional Merge Check`, using the 'Projects / repositories' field and paste the same script you provided here. It should work without errors

 

Screenshot 2022-09-13 at 17.36.58.png

Screenshot 2022-09-13 at 16.44.06.png

 

I hope this helps! Please let us know if you have any questions or any other problems with this.

Kind Regards

Yannis

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events