Jenkins Installation
This guide covers Jenkins deployment using Docker with Blue Ocean UI, including configuration of build tools and private registry integration.
Docker Setup for Jenkins
Create required directories and start the Jenkins container:
mkdir -p ~/jenkins/jenkins_home
mkdir -p ~/jenkins/build_tools
chmod -R 777 ~/jenkins
docker run \
-u root \
-d \
--restart always \
-p 80:8080 \
-p 50000:50000 \
-v ~/jenkins/jenkins_home:/var/jenkins_home \
-v ~/jenkins/build_tools:/var/build_tools \
-v /etc/localtime:/etc/localtime \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkinsci/blueocean
Update Center Configuration
Modify the udpate center XML to use a mirror in China:
vi ~/jenkins/jenkins_home/hudson.model.UpdateCenter.xml
Add the following content:
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>https://mirrors.cloud.tencent.com/jenkins/updates/update-center.json</url>
</site>
</sites>
Restart the container to apply changes:
docker restart <container_id>
Initial Access
Access Jenkins at http://YOU'RE_IP. Retrieve the initial admin password from:
cat ~/jenkins/jenkins_home/secrets/initialAdminPassword
Build Tools Installation
Download and configure the following tools:
- OpenJDK 8
- Node.js 14.x
- Mavan 3.8.x
Set up appropriate environment variables and verify installations in Jenkins global tool configuration.
Credentials Configuration
Configure credentials in Jenkins for Git repository access and private registry authentication. Store GitLab credentials and Harbor registry credentials in the Jenkins credential store.
Pipeline Project Setup
Spring Boot Maven Project
The following configuration demonstrates a complete CI/CD pipeline for a Spring Boot application with Docker image building.
pom.xml Build Configuration
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<configuration>
<repository>${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
Dockerfile
FROM openjdk:8-jdk-alpine
ENV LANG en_US.UTF-8
RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \
&& echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \
&& apk update upgrade \
&& apk add --no-cache procps unzip curl bash tzdata \
&& apk add ttf-dejavu \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ARG JAR_FILE
ADD ${JAR_FILE} /app.jar
ENTRYPOINT ["java", "-jar","/app.jar", "--spring.profiles.active=prod"]
EXPOSE 8101
Jenkinsfile
// GitLab credentials identifier
def git_auth = "gitlab"
// Project name
def project_name = "spring-boot-case-ci"
// Image tag
def tag = "latest"
// Private registry URL
def registry_url = "192.168.44.22"
// Registry project name
def registry_project = "test"
// Registry credentials
def registry_auth = "harbor"
node {
stage('Checkout') {
checkout([
$class: 'GitSCM',
branches: [[name: "*/${branch}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: "${git_auth}", url:"http://192.168.44.24/root/spring-boot-case-ci.git"]]
])
}
stage('Build') {
sh "mvn -v"
sh "java --version"
def imageName = "${project_name}:${tag}"
sh "mvn clean package dockerfile:build"
sh "docker tag ${imageName} ${registry_url}/${registry_project}/${imageName}"
withCredentials([usernamePassword(credentialsId: "${registry_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
sh "docker login -u ${username} -p ${password} ${registry_url}"
sh "docker push ${registry_url}/${registry_project}/${imageName}"
}
sh "docker rmi -f ${imageName}"
sh "docker rmi -f ${registry_url}/${registry_project}/${imageName}"
}
}
Vue.js Frontend Project
The following demonstrates a frontend CI/CD pipeline using Vue.js with Nginx deployment.
nginx.conf/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html = 404;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend-service/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Dockerfile
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
ADD default.conf /etc/nginx/conf.d/
COPY dist/ /usr/share/nginx/html/
EXPOSE 80
Jenkinsfile Build Stage
sh "npm install"
sh "npm run build:prod"
sh "docker build -t ${imageName} ."
Configure a Jenkins pipeline pointing to the Git repository containing these files. The pipeline will execute build steps, construct Docker images, and push them to your private registry for deployment.