How to sit with Gitlab on Github using webhooks

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.

+5
source share
2 answers

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.

I added that the "-publisher" jobs that run after the "" completed successfully. I could do it in one job, but decided to break it down. Assembly work is started using a web hook in GitLab; publisher jobs use the @daily schedule from the BuildResultTrigger plugin.

+2
source
  • will work of course.

  • possible, but dangerous, because the GitLab shell automatically references the hooks in the repository for you, and they are necessary for checking permissions: https://github.com/gitlabhq/gitlab-shell/tree/823aba63e444afa2f45477819770fec3cb5f0159/hooks so I would prefer to stay further From him.

  • Web hooks are not directly suited: they make an HTTP request with a fixed format on certain events, in your case push, not Git protocol requests.

    Of course, you could write a server that consumes hook, clones, and clicks, but a service (single click and no deployment) or GitLab CI (already implementing hook control) would be the best solution.

    / li>
  • services is the best option if someone implements it: live in the source tree, make one click, and do not require additional deployment costs.

  • GitLab CI or other CIs such as Jenkins are the best option currently available. They, in fact, have already implemented a server for webhooks, which automatically clones you: all you have to do is click on them.

The keywords you want to use for Google are "gitlab mirror github". This led me to: Mirroring the Gitlab repository . Today, there seems to be no perfect, simple solution.

It has also already been suggested on the forum with features: http://feedback.gitlab.com/forums/176466-general/suggestions/4614663-automatic-push-to-remote-mirror-repo-after-push-to Always check there ;) Go and increase the request.

The key difficulty right now is to save push credentials.

+2
source

Source: https://habr.com/ru/post/1204572/


All Articles