Docker 安装 Jenkins 2.414

1. 下载 docker 镜像

docker pull jenkins/jenkins:2.414

2. 启动docker镜像

docker run --name=jenkins --net host  -d -p 8088:8080 --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v /home/jenkins:/var/jenkins_home -u 0 -v /home/sky/soft/jdk-11.0.19:/usr/local/jdk -v /home/jenkins/maven:/usr/local/maven -e PHP_TZ="Asia/Shanghai" jenkins/jenkins:2.414

3. 配置国内插件源

1. 修改 default.json
路径:/home/jenkins/updates
修改替换1
https://www.google.com  替换成 https://www.baidu.com 
修改替换2
https://updates.jenkins.io/download  替换成 https://mirrors.tuna.tsinghua.edu.cn/jenkins

2. 修改清华源
Dashboard -> Manage Jenkins -> Plugins
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

4. 安装vim

apt-get update
apt-get install -y vim

5. 配置JAVA_HOME、MAVEN_HOME及PATH

export JAVA_HOME=/usr/local/jdk
export MAVEN_HOME=/usr/local/maven
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH

6. 安装插件

1. build timestamp
2. Localization: Chinese (Simplified)
3. Pipeline: API
4. Credentials
5. SSH Credentials
6. JSch dependency
7. SSH
8. SSH Credentials
9. SSH Build Agents
10. Publish Over SSH
11. SSH Agent
12. SSH Pipeline Steps
13. SCP publisher
14. Mina SSHD API :: SCP
15. Mina SSHD API :: SFTP
16. Git
17. Git client
18. Workspace Cleanup

7. 配置Jenkins全局工具

Dashboard -> 系统管理 -> 全局工具配置

7.1 JDK

Docker 安装 Jenkins 2.414_第1张图片

7.2 Maven

Docker 安装 Jenkins 2.414_第2张图片

8. 新增SSH Server

Docker 安装 Jenkins 2.414_第3张图片

9. 执行shell (构建步骤的一部分)

cd ${WORKSPACE}/xxxx
echo "BUILD_TIMESTAMP 的值为:${BUILD_TIMESTAMP}"
docker build -t image_name:${BUILD_TIMESTAMP} . --build-arg JAR_FILE=./target/image_name.jar
docker login -u admin -p Harbor7uji9olp- 192.168.0.1:5000
docker push image_name:${BUILD_TIMESTAMP}

10. 构建后的步骤

# 登录88
docker login -u admin -p asdfghjkl- 192.168.0.1:5000
# 拉镜像
docker pull image_name:${BUILD_TIMESTAMP}
# 停止原有容器
docker stop container_name
# 删除原有容器
docker rm container_name
# 运行
docker run -d --net=host --name container_name --restart=always image_name:${BUILD_TIMESTAMP}

你可能感兴趣的:(Docker,docker,jenkins)