forked from Yan316/example-product-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile-tke
90 lines (79 loc) · 2.66 KB
/
Jenkinsfile-tke
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
82
83
84
85
86
87
88
89
90
def IMAGE_NAME = 'ccr.ccs.tencentyun.com/my-registry/example-product-service'
def LOCAL_IMAGE = 'net.thoughtworks/example-product-service:latest'
pipeline {
agent any
// agent {
// label 'jnlp-agent'
// }
environment {
DOCKER_CREDENTIALS = credentials('DOCKER_CREDENTIALS')
IMAG_TAG = "${env.BUILD_ID}"
//IMAG_TAG = env.GIT_COMMIT.substring(0,7)
}
options {
timeout(time: 10, unit: 'MINUTES')
}
stages {
stage('clone repository') {
steps {
sh 'echo "Cloning GitHub repository ..."'
checkout scm
}
}
stage('build Project') {
steps {
sh """
./gradlew clean build -Dorg.gradle.daemon=false
"""
}
}
stage('push image') {
steps {
sh """
./gradlew jibDockerBuild
docker tag ${LOCAL_IMAGE} ${IMAGE_NAME}:${IMAG_TAG}
docker login ccr.ccs.tencentyun.com -u ${DOCKER_CREDENTIALS_USR} -p ${DOCKER_CREDENTIALS_PSW}
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 """
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
"""
}
}