Commit 4582653a by kang.li

update file

parent bea364fa
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
def helmDeploy(Map args) { def helmDeploy(Map args) {
if(args.init){ if(args.init){
println "Helm 初始化" println "Helm 初始化"
sh "helm init --client-only --stable-repo-url ${args.url}" sh "helm repo add myrepo ${args.url}"
} else if (args.dry_run) { } else if (args.dry_run) {
println "尝试 Helm 部署,验证是否能正常部署" println "尝试 Helm 部署,验证是否能正常部署"
sh "helm upgrade --install ${args.name} --namespace ${args.namespace} ${args.values} --set ${images},${tag} stable/${args.template} --dry-run --debug" sh "helm upgrade --install ${args.name} --namespace ${args.namespace} ${args.values} --set ${args.image},${args.tag} myrepo/${args.template} --dry-run --debug"
} else { } else {
println "正式 Helm 部署" println "正式 Helm 部署"
sh "helm upgrade --install ${args.name} --namespace ${args.namespace} ${args.values} --set ${images},${tag} stable/${args.template}" sh "helm upgrade --install ${args.name} --namespace ${args.namespace} ${args.values} --set ${args.image},${args.tag} myrepo/${args.template}"
} }
} }
...@@ -20,13 +20,13 @@ timeout(time: 600, unit: 'SECONDS') { ...@@ -20,13 +20,13 @@ timeout(time: 600, unit: 'SECONDS') {
node (label) { node (label) {
stage('Git阶段'){ stage('Git阶段'){
echo "Git 阶段" echo "Git 阶段"
git branch: "master" ,changelog: true , url: "https://github.com/my-dlq/springboot-helloworld.git" git branch: "master" ,changelog: true , url: "http://172.8.10.50/kang.li/springboot-helloworld.git"
} }
stage('Maven阶段'){ stage('Maven阶段'){
echo "Maven 阶段" echo "Maven 阶段"
container('maven') { container('maven') {
//这里引用上面设置的全局的 settings.xml 文件,根据其ID将其引入并创建该文件 //这里引用上面设置的全局的 settings.xml 文件,根据其ID将其引入并创建该文件
configFileProvider([configFile(fileId: "75884c5a-4ec2-4dc0-8d87-58b6b1636f8a", targetLocation: "settings.xml")]){ configFileProvider([configFile(fileId: "f52f21ee-f601-4e6a-89cb-4270f4b2758a", targetLocation: "settings.xml")]){
sh "mvn clean install -Dmaven.test.skip=true --settings settings.xml" sh "mvn clean install -Dmaven.test.skip=true --settings settings.xml"
} }
} }
...@@ -38,11 +38,11 @@ timeout(time: 600, unit: 'SECONDS') { ...@@ -38,11 +38,11 @@ timeout(time: 600, unit: 'SECONDS') {
echo "读取 pom.xml 参数" echo "读取 pom.xml 参数"
pom = readMavenPom file: './pom.xml' pom = readMavenPom file: './pom.xml'
// 设置镜像仓库地址 // 设置镜像仓库地址
hub = "registry.cn-shanghai.aliyuncs.com" hub = "harbor.siger-data.com"
// 设置仓库项目名 // 设置仓库项目名
project_name = "mydlq" project_name = "test"
echo "编译 Docker 镜像" echo "编译 Docker 镜像"
docker.withRegistry("http://${hub}", "ffb3b544-108e-4851-b747-b8a00bfe7ee0") { docker.withRegistry("http://${hub}", "4010cced-1d9c-42df-b3d3-d868c67920b6") {
echo "构建镜像" echo "构建镜像"
// 设置推送到aliyun仓库的mydlq项目下,并用pom里面设置的项目名与版本号打标签 // 设置推送到aliyun仓库的mydlq项目下,并用pom里面设置的项目名与版本号打标签
def customImage = docker.build("${hub}/${project_name}/${pom.artifactId}:${pom.version}") def customImage = docker.build("${hub}/${project_name}/${pom.artifactId}:${pom.version}")
...@@ -55,12 +55,13 @@ timeout(time: 600, unit: 'SECONDS') { ...@@ -55,12 +55,13 @@ timeout(time: 600, unit: 'SECONDS') {
} }
stage('Helm阶段'){ stage('Helm阶段'){
container('helm-kubectl') { container('helm-kubectl') {
withKubeConfig([credentialsId: "8510eda6-e1c7-4535-81af-17626b9575f7",serverUrl: "https://kubernetes.default.svc.cluster.local"]) { withKubeConfig([credentialsId: "88c5b7aa-60f3-4d74-911e-a0183baeb097",serverUrl: "https://kubernetes.default.svc.cluster.local"]) {
// 设置参数 // 设置参数
images = "image.repository=${hub}/${project_name}/${pom.artifactId}" image = "image.repository=${hub}/${project_name}/${pom.artifactId}"
tag = "image.tag=${pom.version}" tag = "image.tag=${pom.version}"
template = "spring-boot" // 设置使用的 chart 并指定版本
repo_url = "http://chart.mydlq.club" template = "spring-boot --version 2.0.2"
repo_url = "http://172.8.10.66/charts"
app_name = "${pom.artifactId}" app_name = "${pom.artifactId}"
// 检测是否存在yaml文件 // 检测是否存在yaml文件
def values = "" def values = ""
...@@ -71,9 +72,9 @@ timeout(time: 600, unit: 'SECONDS') { ...@@ -71,9 +72,9 @@ timeout(time: 600, unit: 'SECONDS') {
echo "Helm 初始化" echo "Helm 初始化"
helmDeploy(init: true ,url: "${repo_url}"); helmDeploy(init: true ,url: "${repo_url}");
echo "Helm 执行部署测试" echo "Helm 执行部署测试"
helmDeploy(init: false ,dry_run: true ,name: "${app_name}" ,namespace: "mydlqcloud" ,image: "${images}" ,tag: "${tag}" , values: "${values}" ,template: "${template}") helmDeploy(init: false ,dry_run: true ,name: "${app_name}" ,namespace: "siger-test" ,image: "${image}" ,tag: "${tag}" , values: "${values}" ,template: "${template}")
echo "Helm 执行正式部署" echo "Helm 执行正式部署"
helmDeploy(init: false ,dry_run: false ,name: "${app_name}" ,namespace: "mydlqcloud",image: "${images}" ,tag: "${tag}" , values: "${values}" ,template: "${template}") helmDeploy(init: false ,dry_run: false ,name: "${app_name}" ,namespace: "siger-test",image: "${image}" ,tag: "${tag}" , values: "${values}" ,template: "${template}")
} }
} }
} }
...@@ -88,10 +89,10 @@ timeout(time: 600, unit: 'SECONDS') { ...@@ -88,10 +89,10 @@ timeout(time: 600, unit: 'SECONDS') {
stage('email'){ stage('email'){
if (currResult == 'SUCCESS') { if (currResult == 'SUCCESS') {
echo "发送成功邮件" echo "发送成功邮件"
emailext(subject: '任务执行成功',to: '3*****7@qq.com',body: '''任务已经成功构建完成...''') emailext(subject: '任务执行成功',to: 'kang.li@siger-data.com',body: '''任务已经成功构建完成...''')
}else { }else {
echo "发送失败邮件" echo "发送失败邮件"
emailext(subject: '任务执行失败',to: '3*****7@qq.com',body: '''任务执行失败构建失败...''') emailext(subject: '任务执行失败',to: 'kang.li@siger-data.com',body: '''任务执行失败构建失败...''')
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment