There are many ways that lead to the goal in IT world. You have to choose the right for your purposes.
In previous post I showed you the most common way to integrate any git repository with Jenkins – I mean SCM Polling. This time I’ll show you an another (GitLab specific) method that opens the door to do Jenkins and GitLab advanced integration such: team collaboration, pull requests, separate branch builting/testing and notifications.
High-level process overview
The previous process looks like below:
Developer performs push to GitLab repository <= Jenkins scans the target repository for chenges every 2 minutes => If change was detected, jenkins builds the project.
This time the process is a little different:
Developer performs push to GitLab repository => GitLab sends a notification to Jenkins => Jenkins builds the project.
With this approach you can integrate Jenkins and GitLab much more, or for different purposes.
- Create a new GitLab project and perform initial commit: J04-gitlab-integration
- Create a freestyle Jenkins project: J04-basic-build and integrate it with GitLab.
- Add the Simple build step and the Simple test step to the J04-basic-build job.
After previous steps you should have GitLab and Jenkins projects configured as below:
Test your job
Building master branch
Clone the J04-gitlab-integration repository and make some change.
git config --global user.name "Tutorial Owner"
git config --global user.email "email@example.com"
git clone http://ubuntu-tutorial:9093/better-coding-tutorials/J04-gitlab-integration.git
echo "Test" >> README.md
git add README.md
git commit -m "GitLab Jenkins integration test"
git push origin master
Open jenkins console. Push to remote repository should trigger a new job instance, but it was failed because “No such file or directory” error.
It’s ok – let’s fix it now by adding some text file with even number of words:
echo "some words" > file01.txt
git add file01.txt
git commit -m "GitLab Jenkins integration test - add file01.txt"
git push origin master
Both steps (build and test) should be successfully completed:
Building custom branch
Previous solution works albo with branches.
git checkout -b test-branch
echo "second file" > file02.txt
git add file02.txt
git commit -m "Add second file to not-master branch"
git push origin test-branch
As you can see the build started and test-branch was checked out.
In the next part I will show you how to integrate Jenkins and GitLab to work with branches (better way) and pull requests.