Question

Hi anyone have a some script may be for example how I can create hook in GitLab repository to automatically build maven war archive from project after each push request? Please post some example of script! Thanks in advance!

Was it helpful?

Solution

You can use a Gitlab-API wrapper to create your hook. There are some in several languages, I'll use the Ruby wrapper as an example. Adding a hook is as simple as :

h = Gitlab.add_project_hook(project_id, hook_url)

Of course, check first if the hook doesn't already exist. Your url could end with /maven .

Your hook will now trigger a POST request on the url everytime something is pushed to the project repo.

A simple webserver such as Sinatra can now handle the request :

mavenjob.rb
require 'sinatra'

post '/maven' do
  'Hook triggered'!
  #Handle creation of maven archive
end

You could consider handling POST requests with a queuing system such as Resque. In case you want to go with Ruby there is a Maven wrapper on Github but I've never used it.

Hope it helps!

OTHER TIPS

My recomodation is to configure gitlab-ci and use it toghether with gitlab. You can also run some other things there and it has very good interface.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top