3 minutes
Replacing Gitlab with Gitea + Jenkins (Part 2)
Intro
This is the followup on the initial post where I started migrating my CI/CD setup from Gitlab to Gitea + Jenkins.
Moving repositories
Deciding to start fresh, I just made new repositories on Gitea and copied over the files.
As an example:
cd /home/rein/homelab_new/
git clone git@gitea:homelab/hugo-website.git
cp -r ../homelab_old/hugo-website .
git add .
git commit -m "initial commit"
git push
ls -la homelab_new/hugo-website
total 60
drwxr-xr-x 8 rein rein 4096 Jul 14 23:03 .
drwxr-xr-x 8 rein rein 4096 Sep 22 18:48 ..
drwxr-xr-x 2 rein rein 4096 Jul 2 11:24 archetypes
-rw-r--r-- 1 rein rein 4379 Nov 5 22:48 config.toml
drwxr-xr-x 3 rein rein 4096 Jul 2 11:24 content
drwxr-xr-x 8 rein rein 4096 Nov 30 18:42 .git
-rw-r--r-- 1 rein rein 27 Jul 2 11:24 .gitignore
-rw-r--r-- 1 rein rein 854 Nov 6 19:50 .gitlab-ci.yml
-rw-r--r-- 1 rein rein 133 Jul 2 11:24 .gitmodules
-rw-r--r-- 1 rein rein 0 Jul 2 11:24 .hugo_build.lock
-rw-r--r-- 1 rein rein 104 Jul 7 11:57 README.md
drwxr-xr-x 3 rein rein 4096 Jul 2 11:24 resources
drwxr-xr-x 3 rein rein 4096 Jul 2 11:24 static
drwxr-xr-x 3 rein rein 4096 Jul 2 11:24 themes
Now that the repository is hosted on Gitea, there is still one thing to do… The repo still has a .gitlab-ci.yml
file. This file has to be converted to a Jenkinsfile
! The Jenkinsfile
is where the pipeline is defined, after some research I created a simple pipeline which will checkout the repo, build the hugo website and finally rysnc
the needed files to my Nginx
server.
Jenkinsfile:
// Jenkinsfile
pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
git branch: 'master', credentialsId: 'jenkins_ssh', url: "${env.REPO_URL}"
}
}
}
stage('Build site') {
steps{
script {
sh "hugo -D -F -d public/"
}
}
}
stage('Rsync to Server') {
steps {
script {
sshagent(['jenkins_ssh']) {
sh "rsync -crtvz --delete -e 'ssh -o StrictHostKeyChecking=no -p ${env.SERVER_PORT}' public/ root@${env.SERVER_HOST}:/usr/share/nginx/html/"
}
}
}
}
}
}
Jenkins connection
Now that I had a repository with a Jenkinsfile
, I could add a new pipeline to the Jenkins server and point it towards that repo. This was done using the following settings:
An extra option that I checked was the "Build Triggers > Poll SCM"
. This will run the pipeline everytime there is a push to master.
Now that the pipeline is build, it needed to be tested ofcourse! This could now be done using a simple commit and push, the Jenkinsfile
will create 4 steps. These steps can be seen in the Jenkins UI:
Success!
Resource impact
Once the new setup was up and running, I checked the resource usage of the new VM. This seemed to be way lower than the Gitlab setup, which is mission accomplished. The +4GB RAM usage went to less than 1.5GB, this gave me some RAM back to use for other projects.
The new setup is working smoothly so far and I’m looking forward to play with Jenkins and see what it can do.