赞
踩
英文:https://www.jenkins.io/
中文:https://www.jenkins.io/zh/
中文文档:https://www.jenkins.io/zh/doc/pipeline/tour/getting-started/
下载地址:https://www.oracle.com/cn/java/technologies/downloads/#java17
mkdir -p /root/jdk
cd /root/jdk
# 下载
https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
# 解压
tar -zxvf jdk-17_linux-x64_bin.tar.gz
下载地址:https://maven.apache.org/download.cgi
mkdir -p /root/maven
cd /root/maven
wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
tar -zxvf apache-maven-3.9.9-bin.tar.gz
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
# 下载安装
yum install git
# 配置git
git config --global user.name "cxf"
git config --global user.email "cxf@qq.com"
@RestController
public class TestController {
@RequestMapping("/test")
public String test(){
return "hello world !";
}
}
提交到gitlab上。
mkdir -p /root/jenkins
cd /root/jenkins
# 下载
wget https://archives.jenkins.io/war-stable/latest/jenkins.war
# 启动报错,需要先安装字体
# java.lang.NullPointerException: Cannot load from short array because "sun.awt.FontConfiguration.head" is null
yum install fontconfig
fc-cache --force
# 后台启动,由于没有设置jdk环境,需要指定全目录
nohup /root/jdk/jdk-17.0.12/bin/java -jar jenkins.war --httpPort=8080 &
tail -f nohup.out
# 启动日志会提示密码
#037d94fa43d74107a8d0dd5424e676e8
#This may also be found at: /root/.jenkins/secrets/initialAdminPassword
访问192.168.56.10:8080
,提示填写密码
,就是启动时日志打印的密码。
点击【安装推荐的插件
】,需要等一段时间自动完成。
下载完插件之后,需要创建第一个 管理员用户 我们设置为admin/admin
。
centos7.9离线安装kubernetes(k8s)1.28版本
centos安装jdk,并提交到Harbor
# 这里我准备好了一个
docker pull registry.cn-hangzhou.aliyuncs.com/cxfpublic/centos:jdk17
1、maven(可选)
2、git参数(下面会用到)
3、其他可选
gitlab、ssh插件(用于远程访问其他主机)
最后,重启jenkins,点击复选框即可。
# 中间三次enter即可
ssh-keygen
# 查看公钥 私钥文件 id_rsa 公钥文件 id_rsa.pub
ls ~/.ssh/
# 将内容拷贝到gitee或gitlab 一般在个人 - 设置中 ssh公钥
cat ~/.ssh/id_rsa.pub
配置好git的用户名和密码即可。
最好别起中文名
# maven需要java环境
export JAVA_HOME=/root/jdk/jdk-17.0.12
export harbor=192.168.56.10:90/library
dateTime=$(date '+%Y%m%d%H%M%S')
# maven打包
/root/maven/apache-maven-3.9.9/bin/mvn clean package -Dmaven.test.skip=true
# 生成dockerfile文件
cat > $WORKSPACE/target/Dockerfile << EOF
FROM ${harbor}/centos:jdk17
MAINTAINER cxf
ADD SpringbootDemo-0.0.1-SNAPSHOT.jar /app.jar
ENTRYPOINT ["/jdk/jdk-17.0.12/bin/java","-jar","/app.jar"]
EXPOSE 8888
EOF
# build
docker build -t ${harbor}/app:1.0 target/.
docker push ${harbor}/app:1.0
docker rmi ${harbor}/app:1.0
最终会在harbor上上传一个镜像。后续使用docker或者k8s就可以直接拉取镜像使用了。
只需要在服务部署的服务器执行:
docker rm -f app
docker rmi -f 192.168.56.10:90/library/app:1.0
docker pull 192.168.56.10:90/library/app:1.0
docker run -p 8888:8888 --name app -d 192.168.56.10:90/library/app:1.0
脚本更新为:
# maven需要java环境
export JAVA_HOME=/root/jdk/jdk-17.0.12
export harbor=192.168.56.10:90/library
dateTime=$(date '+%Y%m%d%H%M%S')
# maven打包
/root/maven/apache-maven-3.9.9/bin/mvn clean package -Dmaven.test.skip=true
# 生成dockerfile文件
cat > $WORKSPACE/target/Dockerfile << EOF
FROM ${harbor}/centos:jdk17
MAINTAINER cxf
ADD SpringbootDemo-0.0.1-SNAPSHOT.jar /app.jar
ENTRYPOINT ["/jdk/jdk-17.0.12/bin/java","-jar","/app.jar"]
EXPOSE 8888
EOF
# build
docker build -t ${harbor}/app:${dateTime} target/.
docker push ${harbor}/app:${dateTime}
docker rmi ${harbor}/app:${dateTime}
curl -X PUT \
-H "content-type: application/json" \
-H "Cookie: KuboardUsername=admin; KuboardAccessKey=fxzcp5mk3pz4.pnjtmz6jjcmnbymaaidyjkffrpriy8pc" \
-d '{"kind":"deployments","namespace":"app","name":"apptest","images":{"192.168.56.10:90/library/app":"192.168.56.10:90/library/app:'${dateTime}'"}}' \
"http://192.168.56.1:30080/kuboard-api/cluster/default/kind/CICDApi/admin/resource/updateImageTag"
新版本改完流水线之后,需要:
https://blog.csdn.net/ethnicitybeta/article/details/141425739
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。