forked from tmax-cloud/hypercloud-console4.2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.hotfix
117 lines (103 loc) · 4.75 KB
/
Jenkinsfile.hotfix
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//input 'Is it OK? \n MAJOR_VERSION=4, MINOR_VERSION=1, PATCH_VERSION=${env.BUILD_NUMBER}, HOTFIX_VERSION=3'
// Script Pipeline
// def CHOICE = input message: 'choice your cloud',
// parameters: [choice(choices: ['kubernetes','196'],
// description: 'need to specify where deploy console app', name: 'Cloud option')]
// def CHOICE = "kubernetes"
// def MAJOR_VERSION = "4"
// def MINOR_VERSION = "1"
def CHOICE = "${params.choice}"
def MAJOR_VERSION = "${params.major_version}"
def MINOR_VERSION = "${params.minor_version}"
def PATCH_VERSION = "${params.patch_version}"
def PRE_VERSION = (("${params.hotfix_version}" as int) - 1).toString()
def HOTFIX_VERSION = "${params.hotfix_version}"
def DOCKER_REGISTRY = "tmaxcloudck"
def PRODUCT = "hypercloud-console"
def VER = "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${HOTFIX_VERSION}"
def PRE_VER = "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${PRE_VERSION}"
// def VER = "1.1.38.1"
def REALM = "${params.realm}"
def KEYCLOAK = "${params.keycloak}"
def CLIENTID = "${params.clientid}"
def BRANCH = "hc-release"
// k8s environment
def NAME_NS = "console-system"
def NODE_PORT = "31304"
def HDC_FLAG = "false"
def PORTAL = "false"
podTemplate(cloud: "${CHOICE}", containers: [
// podTemplate(containers: [
// // podTemplate(cloud: 'kubernetes', containers: [
containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.18.3', command: 'cat', ttyEnabled: true),
// containerTemplate(name: 'ssh-client', image: 'kroniak/ssh-client', command: 'cat', ttyEnabled: true),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
node(POD_LABEL) {
def myRepo = checkout scm
def gitBranch = myRepo.GIT_BRANCH
stage('Input'){
sh "echo 'INSTALL TO ${CHOICE}'"
sh "echo 'PRODUCT=${PRODUCT}'"
sh "echo 'VERSION=${VER}'"
sh "echo 'PREVIOUS_VERSION=${PRE_VER}'"
}
stage('Docker Build'){
container('docker'){
withCredentials([usernamePassword(
credentialsId: 'tmaxcloudck',
usernameVariable: 'DOCKER_USER',
passwordVariable: 'DOCKER_PWD')]){
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PWD}"
sh "docker build -t ${DOCKER_REGISTRY}/${PRODUCT}:${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${HOTFIX_VERSION} -f ./Dockerfile ."
sh "docker push ${DOCKER_REGISTRY}/${PRODUCT}:${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${HOTFIX_VERSION}"
}
}
}
stage('K8S Deploy'){
container('kubectl'){
sh "rm -rf ./temp-yaml"
sh "cp -r ./install-yaml ./temp-yaml"
sh "sed -i 's#@@NAME_NS@@#${NAME_NS}#g' ./temp-yaml/*.yaml"
sh "sed -i 's#@@NODE_PORT@@#${NODE_PORT}#g' ./temp-yaml/install.yaml"
sh "sed -i 's#@@REALM@@#${REALM}#g' ./temp-yaml/install.yaml "
sh "sed -i 's#@@KEYCLOAK@@#${KEYCLOAK}#g' ./temp-yaml/install.yaml "
sh "sed -i 's#@@CLIENTID@@#${CLIENTID}#g' ./temp-yaml/install.yaml "
sh "sed -i 's#@@VER@@#${VER}#g' ./temp-yaml/install.yaml "
sh "sed -i '/--hdc-mode=/d' ./temp-yaml/install.yaml"
sh "sed -i '/--tmaxcloud-portal=/d' ./temp-yaml/install.yaml"
sh "cat ./temp-yaml/install.yaml"
sh "kubectl apply -f ./temp-yaml/install.yaml"
}
}
stage('GIT Commit & Push'){
withCredentials([usernamePassword(credentialsId: 'jinsoo-youn', usernameVariable: 'username', passwordVariable: 'password')]) {
sh """
git config --global user.name ${username}
git config --global user.email [email protected]
git config --global credential.username ${username}
git config --global credential.helper "!echo password=${password}; echo"
"""
sh "git tag ${PRODUCT}_${VER}"
sh "git push origin HEAD:${BRANCH} --tags"
sh """
echo '# hypercloud-console patch note' > ./docs-internal/[HOTFIX]CHANGELOG.md
echo '## [Product Name]_[major].[minor].[patch].[hotfix]' >> ./docs-internal/[HOTFIX]CHANGELOG.md
echo 'Version: ${PRODUCT}_${VER}' >> ./docs-internal/[HOTFIX]CHANGELOG.md
date '+%F %r' >> ./docs-internal/[HOTFIX]CHANGELOG.md
git log --grep=[patch] -F --all-match --no-merges --date-order --reverse \
--pretty=format:\"- %s (%cn) %n Message: %b\" \
--simplify-merges ${PRODUCT}_${PRE_VER}..${PRODUCT}_${VER} \
>> ./docs-internal/[HOTFIX]CHANGELOG.md
"""
//// sh "rm -r ./temp-yaml"
sh "git add -A"
sh "git commit -m 'build ${PRODUCT}_${VER}' "
sh "git push origin HEAD:${BRANCH}"
}
}
}
}