Jenkins安装
1、在docker下安装Jenkins
docker run \
-u root \
-d \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins-data:/var/jenkins_home \
-v /etc/localtime:/etc/localtime:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
--restart=always \
jenkinsci/blueocean
结果
[root@jacson ~]#docker run -u root -d -p 8080:8080 -p 50000:50000 -v jenkins-data:/var/jenkins_home -v /etc/localtime:/etc/localtime:ro -v /var/run/docker.sock:/var/run/docker/sock --restart=always jenkinsci/blueocean
Unable to find image 'jenkinsci/blueocean:latest' locally
latest: Pulling from jenkinsci/blueocean
97518928ae5f: Pull complete
f4d84728e541: Pull complete
419d112ff4fa: Pull complete
ecf8c1881f75: Pull complete
78b59c3bfdb7: Pull complete
2ff43df4e763: Pull complete
aac7818be7cc: Pull complete
2913a3e94ae4: Downloading [======================> ] 32.02MB/72.01MB
f75b1dac4ec0: Download complete
3d3fbe6f1850: Download complete
07ef919d711b: Downloading [==========================> ] 34.65MB/64.51MB
5b96e9c30f6a: Download complete
83dcd37be04b: Download complete
6beb8929489c: Download complete
476e95021232: Download complete
9add339bd1dd: Download complete
ecb71d48971e: Downloading [============> ] 20.47MB/79.82MB
384cd4783059: Waiting
latest: Pulling from jenkinsci/blueocean
df9b9388f04a: Pull complete
caa2071d3c82: Pull complete
8638bf01a5ee: Pull complete
cc97a093f8e8: Pull complete
05543458d7d0: Pull complete
ea18af266852: Pull complete
46ccc7070bae: Pull complete
6936592fc984: Pull complete
88775942d976: Pull complete
3d5d55b046f4: Pull complete
e41fd6a553d4: Pull complete
8f1043079277: Pull complete
5eefb64801a3: Pull complete
68015cce99e1: Pull complete
f2f8661f72b0: Pull complete
9c520de52985: Pull complete
2ab8c197b111: Pull complete
479521d721c8: Pull complete
Digest: sha256:1fdebd0a76e24cccbe6bce50cb61d06c7aa660b8c9340eb86d996675f589f403
Status: Downloaded newer image for jenkinsci/blueocean:latest
26cb2ca2cf523e67dd70af3f03074f47010cfa3c85d67805775bfc994f9bd42b
[root@jacson ~]#
[root@jacson ~]#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26cb2ca2cf52 jenkinsci/blueocean "/sbin/tini -- /usr/…" 25 seconds ago Up 24 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:50000->50000/tcp, :::50000->50000/tcp silly_jepsen
[root@jacson ~]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkinsci/blueocean latest 6955b922b319 22 hours ago 612MB
2、等待安装完成,浏览器输入虚拟机ip+端口号
http://192.168.162.200:8080/
3、获取密码
[root@jacson ~]#docker volume ls
DRIVER VOLUME NAME
local 4abb0c68d61b61608ee522524cda4a2ea0d0bb076b04678ee038f70e4b855b61
local 4f719e41bc3a50e7401d22a129f9fa8e67f8f850da3e0f0250ea8bdc8a363610
local 5c5a31decf3d5489f1115b83f59db31983417fa7dda7a40516bc34dbb27c33d9
local 79c14d4ff8d398fc88d3b3daf0b37d8bcdcab38c27018a8d87d39b6dae3f25b9
local 254554ce07d6574c30b625c1ec74123a8ee6a3c892125a8ea7c5d5d33296102c
local ca1fa2c94f99ab4bbe0ae933e6d0d33e1230de375159ed328b1dc157aac2eaa0
local eb7649c2763f030de7af0554f13a583fb61a6d808c229d09c2185142c1e3e0e8
local jenkins-data
local portainer_data
[root@jacson ~]#docker volume inspect jenkins-data
[
{
"CreatedAt": "2022-05-15T16:44:18+08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/jenkins-data/_data",
"Name": "jenkins-data",
"Options": null,
"Scope": "local"
}
]
[root@jacson ~]#cd /var/lib/docker/volumes/jenkins-data/_data/
[root@jacson /var/lib/docker/volumes/jenkins-data/_data]#ls
config.xml identity.key.enc nodeMonitors.xml secret.key.not-so-secret users
copy_reference_file.log jenkins.telemetry.Correlator.xml nodes secrets war
hudson.model.UpdateCenter.xml jobs plugins updates workflow-libs
hudson.plugins.git.GitTool.xml logs secret.key userContent
[root@jacson /var/lib/docker/volumes/jenkins-data/_data]#cd secrets/
[root@jacson /var/lib/docker/volumes/jenkins-data/_data/secrets]#ls
initialAdminPassword jenkins.model.Jenkins.crumbSalt master.key org.jenkinsci.main.modules.instance_identity.InstanceIdentity.KEY
[root@jacson /var/lib/docker/volumes/jenkins-data/_data/secrets]#cat initialAdminPassword
c6856607bdc04efa915c098a6a8857f6
c6856607bdc04efa915c098a6a8857f6便是密码。
查看容器日志:
docker logs 26cb2ca2cf52
4、一般是直接安装推荐的插件,等待安装完成,注册一个账户即可。
第一个Jenkins流水线项目
Jenkinsfile文件内容
//写流水线的脚本(声明式、脚本式)
pipeline{
//全部的CICD流程都写在这里
//任何一个代理可用就执行
agent any
//定义一些环境信息
//定义流水线的加工流程
stages{
//流水线的所有阶段
//1、编译
//一般双引号是变量,单引号用于常量
stage('编译'){
steps {
//要做的所有事情
echo "编译..."
}
}
//2、测试
stage('测试'){
steps {
//要做的所有事情
echo "测试..."
}
}
//3、打包
stage('打包'){
steps {
//要做的所有事情
echo "打包..."
}
}
//4、部署
stage('部署'){
steps {
//要做的所有事情
echo "部署..."
}
}
}
}