forked from Yan316/example-product-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile-slave
81 lines (69 loc) · 2.46 KB
/
Jenkinsfile-slave
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def IMAGE_NAME = 'ccr.ccs.tencentyun.com/my-registry/example-product-service'
pipeline {
agent {
kubernetes {
yamlFile 'slavePod.yaml'
}
}
environment {
DOCKER_CREDENTIALS = credentials('DOCKER_CREDENTIALS')
IMAG_TAG = "${env.Build_TIMESTAMP}.${env.BUILD_ID}"
// IMAG_TAG = env.GIT_COMMIT.substring(0,7)
}
options {
timeout(time: 10, unit: 'MINUTES')
}
stages {
stage('build Project') {
steps {
sh "LOCAL_ADDRESS=172.27.0.3 ./gradlew clean build -Dorg.gradle.daemon=false"
}
}
stage('push image') {
steps {
sh "docker login ccr.ccs.tencentyun.com -u ${DOCKER_CREDENTIALS_USR} -p ${DOCKER_CREDENTIALS_PSW}"
sh "docker build -t ${IMAGE_NAME}:${IMAG_TAG} ."
sh "docker push ${IMAGE_NAME}:${IMAG_TAG}"
}
}
stage('deploy to dev') {
steps {
deployToStage('dev', 'dev')
}
}
}
post {
always {
publishHTML target: [
allowMissing : false,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : 'build/reports/jacoco/test/html',
reportFiles : 'index.html',
reportName : 'Jacoco Report'
]
publishHTML target: [
allowMissing : false,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : 'build/reports/tests/integrationTest',
reportFiles : 'index.html',
reportName : 'Test Report'
]
}
}
}
def deployToStage(ns, stage) {
withKubeConfig(
caCertificate: '',
contextName: '',
credentialsId: 'k8s-credentials',
serverUrl: 'https://cls-2vcqd9cl.ccs.tencent-cloud.com'
) {
sh "echo 172.27.0.5 cls-2vcqd9cl.ccs.tencent-cloud.com >> /etc/hosts"
sh """
sed \'s/example-product-service:latest/example-product-service:${IMAG_TAG}/g\' './deploy/tencent/app-${stage}.yaml'
kubectl -n ${ns ?: "default"} apply -f './deploy/tencent/app-${stage}.yaml' --force
"""
}
}