193 Star 2.2K Fork 895

贤趣开发小组 / SpringBoot迷你天猫商城(Mini-Tmall)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
K8sJenkinsFile 3.56 KB
一键复制 编辑 原始数据 按行查看 历史
rdc_qa 提交于 2022-03-22 22:39 . 添加私库docker hub地址
pipeline { // 直接上k8s,用k8s来管理docker
agent {
node {
label "maven"
}
}
parameters {
choice(
description: "你需要选择哪条分支进行构建?",
name: "branch_name",
choices: ["master", "feature/k8s_deploy"]
)
}
environment {
// 自建镜像仓库地址
docker_hub = "k8s-harbor:30002"
// 自建harbor仓库的namespace
docker_hub_namespace = "tmall"
// 在jenknis或kubesphere上面的凭证
docker_hub_id = "tmall-zhangjialin-myself-harbor-account"
// k8s 上面的 namespace
k8s_namespace = "tmall-project"
GIT_COMMIT_ID = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
// BUILD_NUMBER 这个变量从jenkins传递过来
current_build_number = "${BUILD_NUMBER}"
// 在k8s上面配置的id
KUBECONFIG_CREDENTIAL_ID = "tmall-kubeconfig"
}
stages {
stage ("打印相关变量") {
steps{
echo "docker_hub_namespace信息为: ${docker_hub_namespace}"
// 获取commit信息,用于后面打tag
echo "commit信息为:${env.GIT_COMMIT_ID}"
echo "current_build_number信息为:${env.current_build_number}"
script {
// 本端tag名
env.local_tag = "tmall:${current_build_number}_${GIT_COMMIT_ID}"
// 远端tag名,必须以这种方式命令,才能push到远端
env.remote_tag = "${docker_hub}/${docker_hub_namespace}/${local_tag}"
echo "local_tag信息为:${env.local_tag}"
echo "remote_tag信息为:${env.remote_tag}"
}
}
}
stage("checkout代码") {
steps {
//git branch: "${branch_name}", credentialsId: 'zhangjialin-youlai-mall-pingzheng', url: 'https://gitee.com/youlaitech/youlai-mall.git'
//checkout([
//$class: 'GitSCM',
//branches: [[name: "${branch_name}"]],
//extensions: [[$class: 'CloneOption', depth: 1, noTags: false, reference: '', shallow: true]],
//userRemoteConfigs: [[credentialsId: 'zhangjialin-youlai-mall-pingzheng', url: 'https://gitee.com/youlaitech/youlai-mall.git']]])
sh "du -h --max-depth=1"
}
}
stage("打包镜像") {
steps {
script {
container ('maven') {
// 最外边
sh "mvn clean install -Dmaven.test.skip=true"
sh "docker build -t ${env.local_tag} -f ./Dockerfile ."
withCredentials([usernamePassword(credentialsId: "${docker_hub_id}", passwordVariable: 'DOCKER_PASSWORD', usernameVariable: 'DOCKER_USERNAME')]) {
sh 'echo "$DOCKER_PASSWORD" | docker login http://k8s-harbor:30002 -u "$DOCKER_USERNAME" --password-stdin'
sh "docker tag ${env.local_tag} ${env.remote_tag}"
sh "docker push ${env.remote_tag}"
}
}
}
}
}
stage("自动部署至k8s") {
agent none
steps {
container ("maven") {
// 这种方式启k8s是官方推荐的
sh 'envsubst < deploy.yaml | kubectl apply -f -'
}
}
}
}
}
Java
1
https://gitee.com/project_team/Tmall_demo.git
git@gitee.com:project_team/Tmall_demo.git
project_team
Tmall_demo
SpringBoot迷你天猫商城(Mini-Tmall)
master

搜索帮助