My google-fu doesn't give me anything that seems obvious if I can only find the right guide.
I have a Gitlab server that was installed by our hosting provider. There are many projects on the Gitlab server. For some of these projects, I want Gitlab to automatically push to a remote repository (in this case Github) every time when switching from a local client to Gitlab. For example: client โ gitlab โ github Any tags and branches should also be pressed.
AFAICT I have 3 options:
- Set up the local client with two remotes and simultaneously press Gitlab and Github. I want to avoid this because the developers.
- Add a post-receive git hook to the repository on the Gitlab server. This would be the most flexible (I have enough Linux experience to write shell scripts like git hooks), and I found documentation on how to do this, but I want to avoid this because then the hosting provider will have to give me shell access.
- I use webhooks in gitlab. I am not familiar with the very basics of webhooks, and I cannot find clear documentation or even a simple step-by-step example. This is the documentation from Gitlab that I found and I donโt understand it: http://demo.gitlab.com/help/web_hooks/web_hooks
I would appreciate good pointers, and I will summarize and document the solution when I find it.
EDIT
I am using this Ruby code for a web hook:
class PewPewPew < Sinatra::Base post '/pew' do push = JSON.parse(request.body.read) puts "I got some JSON: #{push.inspect}" end end
Next: find out how to tell the gitlab server that it should push the repository. I will return to the GitLab API.
EDIT
I think I have an idea. On the server where I run webhook, I pull out from GitLab, and then I click on Github. I can even do some โmagicโ (running tests, building tanks, deploying to Artifactory, ...) before I click on GitHub. Actually, it would be great if Jenkins could click on the remote repository after a successful build, then I would not need to write my own webhook, because I'm sure Jenkins already provides a website for Gitlab, either native or through plugin. But I do not know. Nonetheless.
EDIT
I decided it in Jenkins. You can install more than one git remote in a Jenkins task. I used git Publisher as a Post-Build Action, and it worked like a charm, exactly what I wanted.
source share