-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
36 lines (36 loc) · 1.26 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pipeline {
agent any
environment {
KUBECONFIG_ID = 'k8s_kubeconfig' // Jenkins中配置的kubeconfig秘钥ID
DEPLOYMENT_NAME = 'trpc-demo' // k8s deployment名称
CONTAINER_NAME = 'java' // k8s container名称
IMAGE ='mirrors.tencent.com/trpc-demo/trpc-docker-demo' // 使用的docker image
}
parameters {
// 要更新镜像到的目标tag
string(name: 'IMAGE_TAG', defaultValue: 'latest', description: 'image tag')
}
stages {
// 准备阶段:准备kubectl
stage('Prepare') {
steps {
sh '''
if [ ! -e ~/kubectl ]
then
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubectl
mv kubectl ~/kubectl
chmod +x ~/kubectl
fi
'''
}
}
// 部署阶段:使用kubectl set image命令更新镜像版本
stage('Deploy') {
steps {
withKubeConfig(credentialsId: env.KUBECONFIG_ID) {
sh "~/kubectl set image deployment/${DEPLOYMENT_NAME} ${CONTAINER_NAME}=${IMAGE}:${params.IMAGE_TAG}"
}
}
}
}
}