Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get branch details

How do I get the branch name and last commit date using a groovy script?

1 answer

Hi @Yogesh Mude ,

Please can you tell me how you are using this groovy script?

Is it as a Pre Hook or Merge Check, for example? Or a script you want to run in the Console?

I ask, because knowing where and how the script will be run will affect the script example I can provide you.

Thanks,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hello, @Robert Giddings _Adaptavist_ ,

Thanks for the time and response.

Actually, we have a requirement like every Friday or once in a week bitbucket should send an email listing all open branches.

So for this, I checked in Script Runner there is a Jobs (ie. Schedule Custom Email) using which I can send an email based on the interval.

So here I need to write a script where I can get all detail like Project Name, Open branch Name,  Last commit date, Has open pull request or not, etc..

Can you guide me or provide me any previous script for assistance.

Regards,

Yogesh

Hi @Yogesh Mude ,

If you look at this Community post (https://community.atlassian.com/t5/Adaptavist-questions/Scriptrunner-list-of-tags/qaq-p/1376193) it has a Script on it, that reports on all tags belonging to a repository using the 

com.atlassian.bitbucket.repository.RefService.getTags()

method.

You could use that Script as a basis, but instead you would want to use the 

com.atlassian.bitbucket.repository.RefService.getBranches()

method. The results of which contain the last commit.

Here is the JavaDoc with the details of RefService: https://docs.atlassian.com/bitbucket-server/javadoc/6.9.0/api/com/atlassian/bitbucket/repository/RefService.html

Also, you will also want to use the PullRequestService in order to search for open Pull Requests.

Here is the JavaDoc with the details of the PullRequestService: https://docs.atlassian.com/bitbucket-server/javadoc/6.9.0/api/com/atlassian/bitbucket/pull/PullRequestService.html

Please let me know if you require any more help?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Bitbucket

Contest: Share your custom Bitbucket Pipe and win

Announced in this blog, this holiday season we’re celebrating all things CI/CD and between now and the end of 2019 we’ll be showcasing content, use cases, feature announcements and more. One featur...

2,121 views 11 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you