中医古籍标引
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Jenkinsfile 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. pipeline {
  2. agent {
  3. kubernetes {
  4. cloud 'kubernetes-ACK'
  5. slaveConnectTimeout 1200
  6. workspaceVolume hostPathWorkspaceVolume(hostPath: "/mnt/workspace", readOnly: false)
  7. yaml '''
  8. apiVersion: v1
  9. kind: Pod
  10. spec:
  11. containers:
  12. - args: [\'$(JENKINS_SECRET)\', \'$(JENKINS_NAME)\']
  13. image: 'harbor.51trust.net/zyyl/jnlp-slave:latest'
  14. #image: 'jenkinsci/jnlp-slave:3.36-2'
  15. name: jnlp
  16. imagePullPolicy: IfNotPresent
  17. volumeMounts:
  18. - mountPath: "/etc/localtime"
  19. name: "localtime"
  20. readOnly: false
  21. - command:
  22. - "cat"
  23. env:
  24. - name: "LANGUAGE"
  25. value: "en_US:en"
  26. - name: "LC_ALL"
  27. value: "en_US.UTF-8"
  28. - name: "LANG"
  29. value: "en_US.UTF-8"
  30. image: "harbor.51trust.net/zyyl/node:16.20.0-bullseye"
  31. imagePullPolicy: "IfNotPresent"
  32. name: "build"
  33. tty: true
  34. volumeMounts:
  35. - mountPath: "/etc/localtime"
  36. name: "localtime"
  37. - mountPath: "/root/.m2/"
  38. name: "cachedir"
  39. readOnly: false
  40. - command:
  41. - "cat"
  42. env:
  43. - name: "LANGUAGE"
  44. value: "en_US:en"
  45. - name: "LC_ALL"
  46. value: "en_US.UTF-8"
  47. - name: "LANG"
  48. value: "en_US.UTF-8"
  49. image: "registry.cn-beijing.aliyuncs.com/citools/kubectl:self-1.17"
  50. imagePullPolicy: "IfNotPresent"
  51. name: "kubectl"
  52. tty: true
  53. volumeMounts:
  54. - mountPath: "/etc/localtime"
  55. name: "localtime"
  56. readOnly: false
  57. #配置kaniko slave pod镜像
  58. - command:
  59. - /bin/sh
  60. - -c
  61. args:
  62. - cat
  63. tty: true
  64. volumeMounts:
  65. - name: kaniko-secret
  66. mountPath: /kaniko/.docker
  67. env:
  68. - name: "LANGUAGE"
  69. value: "en_US:en"
  70. - name: "LC_ALL"
  71. value: "en_US.UTF-8"
  72. - name: "LANG"
  73. value: "en_US.UTF-8"
  74. image: registry.cn-beijing.aliyuncs.com/devops-tols/kaniko-executor:debug
  75. imagePullPolicy: Always
  76. name: "kaniko"
  77. tty: true
  78. nodeSelector:
  79. jenkins-build: "true"
  80. volumes:
  81. - name: kaniko-secret
  82. secret:
  83. secretName: kaniko-secret
  84. items:
  85. - key: config.json
  86. path: config.json
  87. - hostPath:
  88. path: "/usr/share/zoneinfo/Asia/Shanghai"
  89. name: "localtime"
  90. - name: "cachedir"
  91. hostPath:
  92. path: "/opt/m2"
  93. '''
  94. }
  95. }
  96. stages {
  97. stage('Pulling Code') {
  98. parallel {
  99. stage('Pulling Code by Jenkins') {
  100. when {
  101. expression {
  102. env.gitlabBranch == null
  103. }
  104. }
  105. steps {
  106. git(changelog: true, poll: true, url: 'https://gitea.51trust.net/front/acupuncture-moxibustion-admin.git', branch: "${BRANCH}", credentialsId: 'GITEA_ACCOUNT')
  107. script {
  108. COMMIT_ID = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
  109. TAG = BUILD_TAG + '-' + COMMIT_ID
  110. println "Current branch is ${BRANCH}, Commit ID is ${COMMIT_ID}, Image TAG is ${TAG}"
  111. }
  112. }
  113. }
  114. stage('Pulling Code by trigger') {
  115. when {
  116. expression {
  117. env.gitlabBranch != null
  118. }
  119. }
  120. steps {
  121. git(url: 'https://gitea.51trust.net/front/acupuncture-moxibustion-admin.git', branch: env.gitlabBranch, changelog: true, poll: true, credentialsId: 'GITEA_ACCOUNT')
  122. script {
  123. COMMIT_ID = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
  124. TAG = BUILD_TAG + '-' + COMMIT_ID
  125. println "Current branch is ${env.gitlabBranch}, Commit ID is ${COMMIT_ID}, Image TAG is ${TAG}"
  126. }
  127. }
  128. }
  129. }
  130. }
  131. stage('Building') {
  132. steps {
  133. container(name: 'build') {
  134. sh """
  135. node -v
  136. npm install --registry=https://registry.npmmirror.com;npm run build:pro
  137. #yarn install --registry=https://registry.npmmirror.com/;yarn build:pro
  138. ls dist/*
  139. """
  140. }
  141. }
  142. }
  143. stage('Docker build for creating image') {
  144. environment {
  145. HARBOR_USER = credentials('HARBOR_ACCOUNT')
  146. }
  147. steps {
  148. container(name: 'kaniko') {
  149. sh """
  150. echo ${HARBOR_USER_USR} ${HARBOR_USER_PSW} ${TAG}
  151. pwd
  152. ls *
  153. mkdir -p repo/${IMAGE_NAME}
  154. cp -r dist/ repo/${IMAGE_NAME}
  155. cp envconfig/Dockerfile repo/${IMAGE_NAME}
  156. cp envconfig/nginx.conf repo/${IMAGE_NAME}
  157. cd repo/${IMAGE_NAME}
  158. ls *
  159. /kaniko/executor -f Dockerfile -c ./ -d ${HARBOR_ADDRESS}/${REGISTRY_DIR}/${IMAGE_NAME}:${TAG} --force
  160. """
  161. }
  162. }
  163. }
  164. stage('Deploying to K8s') {
  165. environment {
  166. MY_KUBECONFIG = credentials('k8s-kubeconfig')
  167. }
  168. steps {
  169. wrap([$class: 'BuildUser']) {
  170. script {
  171. BUILD_USER = "${env.BUILD_USER}"
  172. BUILD_USER_ID ="${BUILD_USER_ID}"
  173. }
  174. }
  175. script {
  176. env.BUILD_USERNAME = "${BUILD_USER}"
  177. env.BUILD_USERNAMEID = "${BUILD_USER_ID}"
  178. }
  179. container(name: 'kubectl'){
  180. sh """
  181. /usr/local/bin/kubectl --kubeconfig $MY_KUBECONFIG set image deploy -l app=${IMAGE_NAME} ${IMAGE_NAME}=${HARBOR_ADDRESS}/${REGISTRY_DIR}/${IMAGE_NAME}:${TAG} -n $NAMESPACE
  182. """
  183. }
  184. }
  185. }
  186. }
  187. environment {
  188. COMMIT_ID = ""
  189. HARBOR_ADDRESS = "harbor.51trust.net"
  190. REGISTRY_DIR = "gfzj"
  191. IMAGE_NAME = "front-acup"
  192. NAMESPACE = "gfzj"
  193. TAG = ""
  194. }
  195. parameters {
  196. gitParameter(branch: '', branchFilter: 'origin/(.*)', defaultValue: '', description: 'Branch for build and deploy', name: 'BRANCH', quickFilterEnabled: false, selectedValue: 'NONE', sortMode: 'NONE', tagFilter: '*', type: 'PT_BRANCH')
  197. }
  198. }