Operations 3 min read

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.

Full-Stack DevOps & Kubernetes
Full-Stack DevOps & Kubernetes
Full-Stack DevOps & Kubernetes
How to Configure Jenkins to Pull Code from GitLab via SSH

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 “金百万”).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdDevOpsGitLabJenkinsSSH
Full-Stack DevOps & Kubernetes
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.