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.
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 -versionInstall 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 -yStart 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 restartJenkins 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
