更新 'Jenkinsfile'

main
newrain001 9 months ago
parent d1c7674119
commit 8067acb1fd
  1. 160
      Jenkinsfile

160
Jenkinsfile vendored

@ -5,67 +5,66 @@ pipeline {
HARBOR_HOST = "registry.cn-hangzhou.aliyuncs.com"
NAMESPACE_NAME = "newrain_wang"
REPOSITORY_NAME = "my-web-app"
TAG = "v3.0"
TAG = "v2.0"
REPLICAS = 4
YAML_PATH = "k8s/"
DEPLOYMENT_NAME = "deploy.yml"
STATUS_URL = "http://qf.jenkins.vip:30210/job/test/${BUILD_NUMBER}"
CONSOLE_URL = "http://qf.jenkins.vip:30210/job/test/${BUILD_NUMBER}/console"
status = "${currentBuild.result}"
}
agent {
kubernetes {
cloud "kubernetes"
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:3107.v665000b_51092-15
args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/etc/localtime"
name: "volume-2"
readOnly: false
- name: kubectl
image: kubesphere/kubectl:v1.22.0
imagePullPolicy: IfNotPresent
tty: true
command: ["cat"]
volumeMounts:
- mountPath: "/etc/localtime"
name: "volume-2"
readOnly: false
- mountPath: "/var/run/docker.sock"
name: "volume-docker"
readOnly: false
- mountPath: "/root/.kube/config"
subPath: config
name: "kubeconfig"
readOnly: false
- name: docker
image: docker:19.03.15-git
command: ['cat']
tty: true
volumeMounts:
- mountPath: "/var/run/docker.sock"
name: "volume-docker"
readOnly: false
volumes:
- name: volume-2
hostPath:
path: "/usr/share/zoneinfo/Asia/Shanghai"
- name: volume-docker
hostPath:
path: "/var/run/docker.sock"
- name: kubeconfig
secret:
secretName: kubeconfig
items:
- key: config
path: config
apiVersion: v1
kind: Pod
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:3107.v665000b_51092-15
args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/etc/localtime"
name: "volume-2"
readOnly: false
- name: kubectl
image: kubesphere/kubectl:v1.22.0
imagePullPolicy: IfNotPresent
tty: true
command: ["cat"]
volumeMounts:
- mountPath: "/etc/localtime"
name: "volume-2"
readOnly: false
- mountPath: "/var/run/docker.sock"
name: "volume-docker"
readOnly: false
- mountPath: "/root/.kube/config"
subPath: config
name: "kubeconfig"
readOnly: false
- name: docker
image: docker:19.03.15-git
command: ['cat']
tty: true
volumeMounts:
- mountPath: "/var/run/docker.sock"
name: "volume-docker"
readOnly: false
volumes:
- name: volume-2
hostPath:
path: "/usr/share/zoneinfo/Asia/Shanghai"
- name: volume-docker
hostPath:
path: "/var/run/docker.sock"
- name: kubeconfig
secret:
secretName: kubeconfig
items:
- key: config
path: config
"""
}
}
@ -83,52 +82,85 @@ spec:
}
}
post {
always {
success {
dingtalk (
robot: '4eabbd09-a21a-40a9-84db-6440c0daebec',
type: 'MARKDOWN',
title: '镜像推送 ${PROJECT_NAME}',
title: '镜像构建成功 ${PROJECT_NAME}',
text: [
'### 项目 ${PROJECT_NAME}',
'---',
'- 状态:<font color=#FF0000 >、$(currentBuild.result) \${currentBuild.result} ${env.status}</font>',
'- 状态:<font color=#00FF00 >成功</font>',
'- 阶段:构建镜像',
'- 版本:${BUILD_NUMBER}',
'- [查看部署详情](${STATUS_URL})',
'- [查看日志Console](${CONSOLE_URL})'
],
at: [
'17694993496'
]
at: ['17694993496']
)
}
failure {
dingtalk (
robot: '4eabbd09-a21a-40a9-84db-6440c0daebec',
type: 'MARKDOWN',
title: '镜像构建失败 ${PROJECT_NAME}',
text: [
'### 项目 ${PROJECT_NAME}',
'---',
'- 状态:<font color=#FF0000 >失败</font>',
'- 阶段:构建镜像',
'- 版本:${BUILD_NUMBER}',
'- [查看部署详情](${STATUS_URL})',
'- [查看日志Console](${CONSOLE_URL})'
],
at: ['17694993496']
)
}
}
}
stage('部署到kubernetes') {
steps {
container('kubectl') {
sh """
sed -i "s/REPLICAS/${env.REPLICAS}/;s/HARBOR_HOST/${env.HARBOR_HOST}/;s/NAMESPACE_NAME/${env.NAMESPACE_NAME}/;s/REPOSITORY_NAME/${env.REPOSITORY_NAME}/;s/TAG/${env.TAG}/" ${env.YAML_PATH}${env.DEPLOYMENT_NAME}
kubectl apply -f ${env.YAML_PATH}
kubectl apply -f ${env.YAML_PATH}${env.DEPLOYMENT_NAME}
"""
}
}
post {
always {
success {
dingtalk (
robot: '4eabbd09-a21a-40a9-84db-6440c0daebec',
type: 'MARKDOWN',
title: '部署成功 ${PROJECT_NAME}',
text: [
'### 项目 ${PROJECT_NAME}',
'---',
'- 状态:<font color=#00FF00 >成功</font>',
'- 阶段:部署到kubernetes',
'- 版本:${BUILD_NUMBER}',
'- [查看部署详情](${STATUS_URL})',
'- [查看日志Console](${CONSOLE_URL})'
],
at: ['17694993496']
)
}
failure {
dingtalk (
robot: '4eabbd09-a21a-40a9-84db-6440c0daebec',
type: 'MARKDOWN',
title: '项目部署 ${PROJECT_NAME}',
title: '部署失败 ${PROJECT_NAME}',
text: [
'### 项目 ${PROJECT_NAME}',
'---',
'- 状态:<font color=#FF0000 >${currentBuild.result}</font>',
'- 状态:<font color=#FF0000 >失败</font>',
'- 阶段:部署到kubernetes',
'- 版本:${BUILD_NUMBER}',
'- [查看部署详情](${STATUS_URL})',
'- [查看日志Console](${CONSOLE_URL})'
],
at: [
'17694993496'
]
at: ['17694993496']
)
}
}

Loading…
Cancel
Save