Forums

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

How to get the repository name, project key using Script runner Post Hooks plugin

pp
Contributor
October 18, 2019

I want to use script runner plugin which will send the body and trigger a remote call to the CI.

As part of the body, I need repository name and project_key details. I am using script Post hooks, Is there a easy way to get those details?

1 answer

1 accepted

0 votes
Answer accepted
Leo
Community Champion
October 18, 2019

Hi @pp

I never tried this, but mostly below snippet should give you the repo name and project key 

import com.atlassian.bitbucket.repository.RepositoryService;
import com.atlassian.bitbucket.repository.Repository;

def repo_name = repository.getName()
def proj_key = repository.getProject().getKey()

 

BR,

Leo

pp
Contributor
October 18, 2019

Hi Leo,

I am new to groovy, learning myself.

The above snippet throws below error:

[Static type checking] variable [repository] is undeclared.

Leo
Community Champion
October 18, 2019

Hi, can you attach your screen shot. I placed my code in the script post-hook but get no error

pp
Contributor
October 21, 2019

Thanks Leo, my bad. I am not getting error too and your code works great.

pp
Contributor
November 25, 2019

@Leo  Is there a bitbucket server API to get the branch name ? I am creating a script posthook using script runner plugin to trigger CI upon a pullrequest merge trigger event.

I need to find the branch name of the pullrequest where it got merged, to send it as a parameter to CI.

I was browsing through the  bitbucket server API's did not find any. Is there a way to get it this info?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events