How to Configure Jenkins to Pull Code from GitLab via SSH
This guide explains how to set up SSH keys on Jenkins and a GitLab repository so Jenkins can securely pull code, detailing the required public‑key addition to the repo, private‑key credential configuration in Jenkins, and a test job to verify the pull.
Assume Jenkins runs on Server-1 with a public key Server-1-public-key and a private key Server1-1-private-key, while the Git repository resides on Server-2.
To enable Jenkins to pull code from the GitLab repository via SSH, the public key of Server-1 must be added to the repository’s authorized keys, and the private key must be stored in Jenkins as a credential.
Add the public key to the Git repository:
Open the repository in GitLab, go to Settings , and paste Server-1-public-key into the SSH keys section.
Configure Jenkins to use the private key:
Log into Jenkins, navigate to Manage Jenkins → Manage Credentials , add a new credential of type “SSH Username with private key”, and paste Server1-1-private-key.
Create a test job to verify the pull:
Define a new pipeline or freestyle job that runs a git clone or git pull from the repository.
After the job runs successfully, the source code appears in the Jenkins workspace, for example /var/lib/jenkins/workspace/test_git .
Source: reproduced from CSDN (author “金百万”).
Full-Stack DevOps & Kubernetes
Focused on sharing DevOps, Kubernetes, Linux, Docker, Istio, microservices, Spring Cloud, Python, Go, databases, Nginx, Tomcat, cloud computing, and related technologies.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
