Docker安装jenkins
Docker
安装jenkins
一、环境准备
1. 宿主机准备
宿主机安装JDK\MAVEN\GIT\DOCKER\NPM
2. 镜像准备
jenkins/jenkins:latest-jdk8
二、
jenkins
部署
1.镜像下载docker pull jenkins/jenkins:latest-jdk8
docker images | grep jenkins
2.查看镜像版本
docker inspect 44f8e2d8566c
3.启动脚本
restart.sh
- 挂载
docker
目录,容器里可以执行docker
命令- 改用
jenkins/jenkins:latest-jdk8
版本镜像,可以安装gitlab hook
- 挂载
maven
|npm
等目录 ,jdk
默认是:jdk8
。否则容器内无法使用构建命令maven
要做好私服配置,仓库管理等
#!/bin/bashdocker stop jenkins && docker rm jenkinsdocker run -d --name jenkins \
-u root \
--privileged=true \
--restart=always\
-p 8080:8080 -p 5000:5000 \
-v /usr/local/jenkins:/var/jenkins_home \
-v /toony/server/apache-maven-3.6.3:/usr/local/maven \
-v /usr/bin/docker:/usr/bin/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/localtime:/etc/localtime \
-v /root/.ssh:/root/.ssh \
jenkins/jenkins:latest-jdk8#---- jenkinsci/blueocean 默认使用jdk11版本,安装gitlab hook失败 ------#!/bin/bashdocker stop jenkins && docker rm jenkinsdocker run -d --name jenkins \
-u root \
-p 8080:8080 -p 5000:5000 \
-v /toony/jenkins/jenkins_home:/var/jenkins_home \
-v /usr/local/java/jdk1.8.0_171:/var/jenkins_home/jdk8 \
-v /toony/server/apache-maven-3.6.3:/var/jenkins_home/maven \
-v /toony/jenkins/jenkinsci:/usr/jenkinsci \
-v /usr/bin/docker:/usr/bin/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkinsci/blueocean
docker-compose.yml
cat > docker-compose.yml <<-EOF
version: '3'
services:
docker_jenkins:
user: root
restart: always
image: jenkins/jenkins:lts
container_name: jenkins
ports:
- 8080:8080
- 5000:5000
volumes:
- /toony/jenkins/jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /usr/local/bin/docker-compose:/usr/local/bin/docker-compose
docker_nginx:
restart: always
image: nginx
container_name: nginx
ports:
- 8090:80
- 80:80
- 433:433
volumes:
- /toony/nginx/conf.d/:/etc/nginx/conf.d
- /toony/webserver/static/jenkins/dist/dist:/usr/share/nginx/html
EOF
4.配置插件镜像加速
- 将
url
https://updates.jenkins.io/update-center.json
- 修改为 清华大学官方镜像:
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
cd /usr/local/jenkins/
vim hudson.model.UpdateCenter.xml
5.访问
http://http://xxx.61.41.102:8080
- 用户密码:admin
cat /usr/local/jenkins/secrets/initialAdminPassword
或
docker exec -it jenkins bash cat /var/jenkins_home/secrets/initialAdminPassword
6.插件安装
Jenkins -> Manage Jenkins -> System Configuration -> Manage Plugins -> Avaliable
Maven Integration
GitLab
GitLab Hook
SaltStack
Publish Over SSH
Git Parameter
Build With Parameters
Ansible
Build Pipeline
Parameterized Trigger
Parameterized Remote Trigger
Localization: Chinese (Simplified)
文章图片
三、
jenkins
配置
1.全局配置Jenkins -> Manage Jenkins -> System Configuration -> Global Tool Configuration2.配置访问
jdk
|maven
|git
|npm
gitlab
Jenkins -> Manage Jenkins -> Security -> Manage Credentials -> Stores scoped to Jenkins -> global -> Add Credentials -> Username 或者 SSH3. 配置
Push SSH Server
Jenkins -> Manage Jenkins -> System Configuration -> Publish over SSH -> SSH Servers -> Add -> Name|Hostname|Username|Remote Directory -> Use password authentication, or use a different key四、配置
gitlab
触发webhook
1. gitlabz设置root用户可以通过SSH方式拉取代码
2. Jenkins安装好插件:Credentials Plugin|Gitlab Plugin|SSH Plugin|GitLab Hook
3. jenkins添加gitlab的root用户私钥,以便后期拉取代码
4. jenkins项目构建中增加触发器:Build Triggers -> Build when a change is pushed to GitLab -> Generate
保存:webhook URL 和 `secret token`
5. gitlab项目中:Settings -> Webhooks 添加URL和Secret token
- 增加触发器
文章图片
- 生成
secret token
文章图片
Localization: Chinese (Simplified)
Locale plugin
2.全局配置
Jenkins -> Manage Jenkins -> System Configuration -> Local -> Default Language :六、集成zh_CN
勾选Ignore browser ...
SonarQube
1.安装插件SonarQube Scanner for Jenkins
2.
SonarQube
创建Jenkins
登录token
文章图片
3.
Jenkins
配置访问SonarQube
凭据Jenkins -> Manage Jenkins -> Manage Credentials -> Stores scoped to Jenkins -> global -> Add Credentials -> Kind -> Secret text -> 填入4.token
文章图片
Jenkins
系统配置Jenkins -> Manage Jenkins -> System Configuration -> SonarQube servers ->5.Name、Server URL、Server authentication token
文章图片
Jenkins
全局配置Jenkins -> Manage Jenkins -> Global Tool Configuration ->6.项目中配置配置 SonarQube Scanner
文章图片
说明
sonar.projectKey=test_01# SonarQube中项目的唯一标识符。只要它是唯一的
sonar.projectName=test_server# SonarQube中项目显示的名称
sonar.version=0.0.1-SNAPSHOT# 版本号
sonar.sources=./src# 源码目录
sonar.java.binaries=./target/classes# 编译后的文件目录
# sonar.exclusions=**/*.xml,**/*.html#排除不需要检测的文件,如:xml、html
sonar.language=java# 编程语言
sonar.sourceEncoding=UTF-8
sonar.scm.disabled=true
【Docker安装jenkins】
文章图片
七、参考博客
- jenkins jenkinsci/blueocean 使用
- docker安装jenkinsci/blueocean并且创建pipeline项目
- docker安装配置jenkins,并部署到其他服务器
- 使用docker部署jenkins(jdk11)
- Centos 7.8下部署Jenkins Blue Ocean-Docker版
- docker安装Jenkins、jenkins插件、映射JDK和maven和RSA、publish over ssh发布
- Docker手把手部署jenkins教程,jenkins容器带jdk,maven,docker,git
- Jenkins的安装及中文展示、安装插件创建
- ★★ 配置Jenkins自动拉取gitlab中的代码并部署
- ★★ sonarQube部署及Jenkins集成sonarQube
- jenkins+sonar 持续集成检测代码质量
推荐阅读
- Docker应用:容器间通信与Mariadb数据库主从复制
- Mac安装Chromedriver
- MongoDB,Wondows下免安装版|MongoDB,Wondows下免安装版 (简化版操作)
- MAC安装Mongo
- 【Hadoop踩雷】Mac下安装Hadoop3以及Java版本问题
- react|react 安装
- VueX--VUE核心插件
- python-安装sublime遇到异常
- typeScript入门基础介绍
- docker镜像探索----dive工具