Operations 6 min read

How to Set Up Jenkins with GitHub on CentOS 7: A Step‑by‑Step Guide

This guide walks you through preparing a CentOS 7.4 environment with JDK 1.8, installing Jenkins via yum, configuring Jenkins to communicate with GitHub using webhooks and personal access tokens, and creating a freestyle job that pulls source code, builds, and runs automatically.

Full-Stack DevOps & Kubernetes
Full-Stack DevOps & Kubernetes
Full-Stack DevOps & Kubernetes
How to Set Up Jenkins with GitHub on CentOS 7: A Step‑by‑Step Guide

Environment

CentOS 7.4

JDK 1.8

Installation Steps

Install JDK

Install Jenkins

Configure Jenkins–GitHub integration

Create and configure a Jenkins job

Install JDK

Download JDK 8 from Oracle, extract the archive, and set the required environment variables.

cd /usr/local/src
wget <em>your_download_url</em>
 tar -zxvf jdk-8u91-linux-x64.tar.gz
# Add to /etc/profile
JAVA_HOME=/usr/local/tools/jdk1.8.0_144
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib/dt.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH
source /etc/profile
java -version

Install Jenkins

Enable the fastest‑mirror plugin, add the Jenkins repository, import the GPG key, and install Jenkins.

# Install fastest‑mirror
yum install yum-fastestmirror -y

# Add Jenkins repository
sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo

# Import GPG key
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key

# Install Jenkins
yum install jenkins -y

Start Jenkins and optionally change the default port (8080) by editing /etc/sysconfig/jenkins.

service jenkins start
vim /etc/sysconfig/jenkins   # modify JENKINS_PORT if needed
service jenkins restart

Jenkins and GitHub configuration

Initialize Jenkins by opening http://<em>your_ip</em>:8080, retrieve the initial admin password from /var/lib/jenkins/secrets/initialAdminPassword, install suggested plugins, and create an admin account.

Generate a Personal Access Token on GitHub (Settings → Developer settings → Personal access tokens) and copy it.

Configure a webhook in the GitHub repository: Settings → Webhooks → Add webhook, set the payload URL to http://<em>jenkins_ip</em>:8080/github-webhook/, content type application/json, and enable the push event.

In Jenkins, add a GitHub server:

Navigate to “Manage Jenkins” → “Configure System”.

Under “GitHub”, click “Add GitHub Server”.

API URL: https://api.github.com.

Add the GitHub token as a “Secret Text”.

Create and configure a Jenkins job

From the Jenkins dashboard click “New Item”, select “Freestyle project”, and give it a name.

In “Source Code Management” choose “Git” and enter the repository URL.

Enable “GitHub hook trigger for GITScm” under “Build Triggers”.

Add build steps (e.g., shell commands) to compile, test, or package the project.

When saved, Jenkins clones the repository into /var/lib/jenkins/workspace/ and executes the defined script.

Notes

Ensure any required global scripts are symlinked into /usr/bin so Jenkins can invoke them.

If a custom port is used, update the webhook payload URL accordingly.

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/cdautomationDevOpsJDKGitHubJenkinsCentOS
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.