How to use GitLab CICD with GitHub Repository
Imagine that your all repos are hosted on GitHub but you wanna use GitLab's CI/CD for them instead of GitHub actions. So, in today's article, I am going to show you, how we can use GitLab CICD with GitHub Repository.
Create GitHub Access Token
To connect our GitHub Repositories with GitLab, we need to create a GitHub Access Token. You should have GitHub Owner Role to perfome this action
To create a GitHub Access Token, follow the steps below:
- Go to your GitHub account and navigate to Settings->token->new
- Create a Personal Access Token
- Give it a description(optional) and update the scope to allow repo and admin:repo_hook. By allowing above scopes, GitLab can access your project, update commit statuses, and create a web hook to notify GitLab of new commits
Note: You need to store this Access Token in a safe place because we need this Token for our future steps
Create new GitLab project
Now, we need to create a new GitLab project. To create a new project, follow the steps below:
- Navigate to Projects-> Create new project
- Select Run CI/CD for external repository
- Select GitHub as the source
- Enter your GitHub Access Token
- Search your GitHub Repository name and import it
Configure Pull Mirroring
Now, we need to enable Pull Mirroring for our GitLab project, follow the steps below:
- Navigate to your imported project
- Then navigate to Settings->Repository->Mirroring repositories
- Now expand it and add details related to your project and configure other settings according to your requirements
- After all click on Mirror Repository
Add .gitlab-ci.yml to GitHub project
Finally navigate to your GitHub Project and add .gitlab-ci.yml file. This file contains all the CI/CD configuration for your project. In this GitHub repository, I have provided simple CI/CD configuration for testing our pipeline is working. Now, we need to make a little change on our local project and push it to the the GitHub. Now, You can see it will run our pipline in GitLab project's pipeline sction successfully.
Conclusion
In this tutorial, we learned how we can use GitLab CICD with GitHub Repository. If you have any issue regarding this tutorial, mention your issue in comment section or reach me through my E-mail.
Happy Coding
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
Comments
GitalkDisqus