Jenkins Overview
Jenkins is an open-source automation server written in Java that helps automate the building, testing, and deployment of software. It provides hundreds of plugins to support building, deploying, and automating any project. Originally known as Hudson, Jenkins has evolved into a powerful CI/CD tool.
Key Features:
- Open-source and free
- Cross-platform compatibility
- Master-slave architecture for distributed builds
- Web-based graphical interface
- Simple installation and configuration
- 200+ available plugins
Installation Steps
Prerequisites
Before installing Jenkins, ensure you have Java Development Kit (JDK) installed. Jenkins requires Java 8 or later.
Installation via WAR File
Download the Jenkins WAR file from the official site. After downloading, execute the following command:
nohup java -jar jenkins.war --httpPort=8888 &Access Jenkins through your browser at http://your-server-ip:8888. Follow the on-screen instructions to complete the initial setup, including creating an admin account and installing recommended plugins.
Environment Setup
JDK Configuration
First, check for existing Java installations:
java -versionIf you need to remove OpenJDK:
rpm -qa | grep java
rpm -e --nodeps [package-name]Extract and install Oracle JDK:
tar -xvf jdk-8u144-linux-x64.tar.gz
mv jdk1.8.0_144 /opt/java
mv jdk1.8.0_144 jdk1.8Configure environment variables:
vim /etc/profileAdd these lines:
export JAVA_HOME=/opt/java/jdk1.8
export JRE_HOME=/opt/java/jdk1.8/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=.:${JAVA_HOME}/bin:$PATHApply changes:
source /etc/profile
java -versionMaven Installation
Extract Maven to /opt directory and configure settings.xml:
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>Set Maven environment variables:
export MAVEN_HOME=/opt/apache-maven-3.5.0
export PATH=.:${JAVA_HOME}/bin:$MAVEN_HOME/bin:$PATHGit Configuration
Install Git if not present and configure SSH keys:
git config --global user.name "username"
git config --global user.email "email@example.com"
ssh-keygen -t rsa -C "email@example.com"
Copy the public key to your Git provider account.
Node.js Setup
tar -zxvf node-v11.15.0-linux-x64.tar.gz
mv node-v11.15.0-linux-arm64/ nodejs
mv nodejs/* /usr/local/nodejs
ln -s /usr/local/nodejs/bin/node /usr/local/bin
ln -s /usr/local/nodejs/bin/npm /usr/local/bin
npm install -g yarn
ln -s /usr/local/nodejs/bin/yarn /usr/local/binJenkins Configuration
Essential Plugins
Install these plugins via Manage Jenkins → Manage Plugins:
- Maven Integration
- Git Parameter Plug-In
- Publish over SSH
- ThinBackup
System Configuration
Navigate to Manage Jenkins → Configure System. Set up paths for JDK, Maven, Git, and Node.js. Configure SSH servers for remote deployment.
Project Configuration
Java Project Setup
- Create a new Maven project
- Configure Git repository and branch selection
- Set build goals (e.g.,
clean install) - Configure post-build actions for SSH deployment
Frontend Project Setup
- Create a Freestyle project
- Configure Git repository
- Add build steps:
npm install --unsafe-perm=true
chmod -R 777 node_modules/
npm run build- Set up artifact transfer via SSH
Advanced Configuration
Custom Workspace
In project configuration, enable "Use custom workspace" to specify a custom directory for code checkout.
Project Dependencies
Set up project relationships where Project A depends on Project B. Configure Project A to build automatically after successful completion of Project B.
Parameterized Builds
Enable "This project is parameterized" to allow runtime parameter selection, such as Git branches.
Backup Configuration
Use the ThinBackup plugin to regularly back up Jenkins configurations.
Troubleshooting Common Issues
Git Clone Errors (Status 128)
Verify SSH key configuration and test with manual git clone from the Jenkins server.
SSH Key Format Issues
Generate compatible SSH keys:
ssh-keygen -m PEM -t rsa -b 4096Node.js Build Failures
For node-sass errors, use:
npm install --unsafe-perm=trueFor permission issues:
npm install && chmod -R 777 node_modules/ && npm run buildDependency Version Conflicts
For Vue-related errors:
npm install @vue/compiler-sfcFor engine incompatibility warnings:
yarn config set ignore-engines true