项目说明

部署思路
- 克隆代码
- 编译打包
- 构建镜像
- 将镜像推送到本地镜像仓库
- 修改 k8s.yaml 文件的 tag
- 应用资源清单 k8s.yaml
podTemplate(cloud: 'kubernetes',containers: [
containerTemplate(name: 'tools', image: 'registry.cn-beijing.aliyuncs.com/dengyou/kube-ops:tools', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'maven3', image: 'registry.cn-beijing.aliyuncs.com/dengyou/kube-ops:maven3', command: 'cat', ttyEnabled: true),
],
volumes: [
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
hostPathVolume(hostPath: '/root/.kube/', mountPath: '/root/.kube/'),
hostPathVolume(hostPath: '/root/.docker', mountPath: '/root/.docker'),
hostPathVolume(hostPath: '/data/repo', mountPath: '/usr/local/apache-maven/repo')
]
)
{
node(POD_LABEL) {
stage('Clone'){
container('tools') {
echo "1. Clone Stage"
git url: "https://github.com/imirsh/mvnweb-demo.git"
script {
build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
}
}
}
stage('Package') {
container('maven3') {
echo "3. Package From Source Code"
sh "mvn install"
}
}
stage('Build') {
container('tools') {
echo "3. Build Docker Image Stage"
sh "docker build -t registry.cn-beijing.aliyuncs.com/dengyou/mvnweb-demo:${build_tag} ."
}
}
stage('Push') {
container('tools') {
echo "4. Push Docker Image Stage"
sh "docker push registry.cn-beijing.aliyuncs.com/dengyou/mvnweb-demo:${build_tag}"
}
}
stage('YAML') {
container('tools'){
sh "sed -i 's@<BUILD_TAG>@${build_tag}@g' k8s.yaml"
sh '/usr/local/bin/kubectl apply -f k8s.yaml --record'
}
}
}
}

【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步