day22
回顾
Jenkins
简介
官网Jenkins
Jenkins Build great things at any scale
The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
用来构建一切
其实就是用Java写的一个项目,最后打包为一个war包,执行这个war包就可以运行起来了
但是官网最新的war包要求必须是jdk17以上(17,21)
[root@work day22]# java -jar jenkins.war Running with Java 11 from /usr/lib/jvm/java-11-openjdk-11.0.25.0.9-2.el9.x86_64, which is older than the minimum required version (Java 17). Supported Java versions are: [17, 21]
所以我们用docker来搭建
环境搭建
使用docker搭建jenkinsDownload and deploy
部署网络环境
docker network create jenkins
执行docker运行命令
docker run --name jenkins-docker --rm --detach \ --privileged --network jenkins --network-alias docker \ --env DOCKER_TLS_CERTDIR=/certs \ --volume jenkins-docker-certs:/certs/client \ --volume jenkins-data:/var/jenkins_home \ --publish 2376:2376 \ docker:dind --storage-driver overlay2
新建Dockerfile文件
FROM jenkins/jenkins:2.479.1-jdk17 USER root 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 echo "deb [arch=$(dpkg --print-architecture) \ signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \ https://download.docker.com/linux/debian \ $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list RUN apt-get update && apt-get install -y docker-ce-cli USER jenkins RUN jenkins-plugin-cli --plugins "blueocean docker-workflow"
官方给的是这个jenkins/jenkins:2.479.1-jdk17,从这里也可以看出来,这个jenkins用的jdk是17的版本。这也就是我为什么用docker,而不用单纯的war包方式了。但是这个镜像有问题,我做了修改jenkins/jenkins:latest
FROM jenkins/jenkins:latest USER root 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 echo "deb [arch=$(dpkg --print-architecture) \ signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \ https://download.docker.com/linux/debian \ $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list RUN apt-get update && apt-get install -y docker-ce-cli USER jenkins RUN jenkins-plugin-cli --plugins "blueocean docker-workflow"
在这之前,可以先拉取一下这个镜像
docker pull jenkins/jenkins:latest
用上面的Dockerfile文件制作镜像
docker build -t myjenkins-blueocean:2.479.1-1 .
检查制作好的镜像
运行我们制作好的镜像
docker run --name jenkins-blueocean --restart=on-failure --detach \ --network jenkins --env DOCKER_HOST=tcp://docker:2376 \ --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 \ --publish 8080:8080 --publish 50000:50000 \ --volume jenkins-data:/var/jenkins_home \ --volume jenkins-docker-certs:/certs/client:ro \ myjenkins-blueocean:2.479.1-1
浏览器访问运行8080端口,到这个登录页面至此jenkins安装部署完成
jenkins使用
第一次登录jenkins这个页面(如上图),我们发现是需要密码的,并且页面上提示我们登录密码的位置在这里/var/jenkins_home/secrets/initialAdminPassword
我们需要执行命令得到jenkins的密码
docker exec Jenkins的容器id cat /var/jenkins_home/secrets/initialAdminPassword
[root@work ~]# docker exec 6627 cat /var/jenkins_home/secrets/initialAdminPassword 0d11bde19338473ead2da58dc1a6fe86
在以上的登录页面中输入刚刚得到的密码,就可以进入jenkins页面了。