基于Docker安装

# 1. 创建网络

docker network create jenkins

# 2. 创建并运行jenkins-docker容器

docker run \
  --name jenkins-docker \
  --detach \
  --privileged \
  --network jenkins \
  --network-alias docker \
  --env DOCKER_TLS_CERTDIR=/certs \
  --volume /home/jenkins/certs/client:/certs/client \
  --volume /home/jenkins/data:/var/jenkins_home \
  --publish 2376:2376 \
  docker:dind \
  --storage-driver overlay2
1
2
3
4
5
6
7
8
9
10
11
12

# 3. 添加Docker中163镜像仓库

vi etc/docker/daemon.json

{
    "registry-mirrors": [ "http://hub-mirror.c.163.com"] }
}
1
2
3

systemctl daemon-reload

systemctl restart docker

# 3. 创建jenkins-blueocean Dockerfile

vi Dockerfile

填入如下内容:

FROM jenkins/jenkins:2.332.1-jdk11
USER root


RUN echo "deb http://mirrors.aliyun.com/debian stretch main contrib non-free" > /etc/apt/sources.list.d/docker.list

RUN echo "deb-src http://mirrors.aliyun.com/debian stretch main contrib non-free" > /etc/apt/sources.list.d/docker.list

RUN echo "deb http://mirrors.aliyun.com/debian stretch-updates main contrib non-free" > /etc/apt/sources.list.d/docker.list

RUN echo "deb-src http://mirrors.aliyun.com/debian stretch-updates main contrib non-free" > /etc/apt/sources.list.d/docker.list

RUN echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free" > /etc/apt/sources.list.d/docker.list

RUN echo "deb-src http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free" > /etc/apt/sources.list.d/docker.list

RUN  apt-get clean

RUN apt-get update && apt-get install -y lsb-release

RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \
  https://download.docker.com/linux/debian/gpg
  
RUN apt-get update && apt-get install -y docker-ce-cli

USER jenkins

RUN jenkins-plugin-cli --plugins "blueocean:1.25.3 docker-workflow:1.28"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# 4. Build jenkins-blueocean

docker build -t myjenkins-blueocean:2.332.1-1 .

ERROR:

# 5. 创建并运行jenkins-blueocean容器

 docker run \
  --name jenkins-blueocean \
  --detach \
  --network jenkins \
  --env DOCKER_HOST=tcp://docker:2376 \
  --env DOCKER_CERT_PATH=/certs/client \
  --env DOCKER_TLS_VERIFY=1 \
  --publish 8899:8080 \
  --publish 50000:50000 \
  --volume /home/jenkins/data:/var/jenkins_home \
  --volume /home/jenkins/certs:ro:/certs/client:ro \
  myjenkins-blueocean:2.332.1-1 
1
2
3
4
5
6
7
8
9
10
11
12

# 6. 解锁

# 6.1 获取密码

sudo docker exec ${CONTAINER_ID or CONTAINER_NAME} cat /var/jenkins_home/secrets/initialAdminPassword

# 6.2 登录

打开浏览器,访问 http://localhost:8899

更新时间: 12/13/2022, 7:50:55 PM