Automated Git Mirror With GitHub or Gitlab or Bitbucket

Experience with Gitlab CI

Git Mirror from Gitlab to Bitbucket using Gitlab CI

Git Mirror from Gitlab to Bitbucket using Gitlab CI

Had to move from BitBucket to Gitlab; which is really great, btw. However, there was one tiny issue here - Gitlab was not supported by Shippable. As you may know already Shippable is a hosted cloud platform that provides hosted continuous integration. We use it in our current setup to do a full testing and deployment onto AWS Elastic Beanstalk.

Since we were moving to Gitlab I wanted to continue using Shippable for our prod deployments. Shippable only supports Github or Bitbucket and therein lies the problem. Gitlab did not work with Circl CI or Travis CI or Shippable or Wercker so I tried using Gitlab CI.

However, there were some issues with it:

I tried using the same yaml was Shippable but it was just not working with too many errors being reported and not to mention, having to wait for an hour during the worst period to see results. Shippable on the other hand, would hand over the console and results within 5 minutes of my commits. Decided to ditch Gitlab CI.

Using Git Mirror

Since Gitlab CI was clearing not working I decided to continue using Shippable. The only issue was, code had to exist in Bitbucket. For that, I needed a git mirror from Gitlab to Bitbucket. Looking into docs I found this link - Other options mentioned setting up configs to add a mirror. For example, look here:

I had a major problem with all the options - every developer had to set it up for this to work on every commit.

I looked into webhooks and triggers on Gitlab but webhooks would have old code (unless I updated the code manually before loading).

Finally, the only way I saw fit to fix this issue was the Gitlab CI itself. I set up a git push as a one-step CI on Gitlab itself. This would do the following:

Here’s my .gitlab-ci.yml

  - deploy

  stage: deploy
    - git push --mirror

Note: Remember to use variables in Gitlab CI to set up your bitbucket username and password. This had to be done because you can’t have any ssh key from Gitlab to add it to Bitbucket

comments powered by Disqus