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

Read git push options with groovy pre-receive hook

yael June 20, 2019

Hi all,

I wish to create a custom groovy pre-receive hook to intercept git push operation + push options sent by this syntax for example:
>>> git push -o topic=master

I easily wrote a bash script to read these options, as described in this link:
https://git-scm.com/docs/githooks#post-receive

and placed it in the Bitbucket server repository directory: <BITBUCKET_HOME>/shared/data/repositories/<REPO_ID>/hooks/pre-receive.d.

This script prints GIT_PUSH_OPTION_COUNT, GIT_PUSH_OPTION_0:

echo $GIT_PUSH_OPTION_COUNT
echo $GIT_PUSH_OPTION_0

I would like to achieve the same behavior using JAVA/GROOVY with Bitbucket API, and read the GIT_PUSH_OPTIONS variables. I found that I can use scmHookDetails.getEnvironment() class to read these variables, however I saw in the API changelog that this class is deprecated in Bitbucket v6 (which we plan to upgrade soon):
https://developer.atlassian.com/server/bitbucket/reference/api-changelog/

What are my other options? Can I use System.getenv to get all groovy environment variables instead?

Thanks!!

Yael

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events