Jenkinsfile 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * gateway:仅晋升 Harbor 镜像 + 可选 ACK。
  3. * Job:Gateway-K8s | Script Path: docs/jenkins/produ/gateway/Jenkinsfile
  4. *
  5. * 与 Job「轻量级检出」配合:不拉 alien-* 业务源码,仅稀疏拉取 _shared 后 load。
  6. */
  7. def SVC = [prodDir: 'gateway', deployName: 'gateway']
  8. /** 稀疏检出流水线共享库(勿拉全仓业务代码) */
  9. def sparseCheckoutProduShared() {
  10. checkout scm: [
  11. $class: 'GitSCM',
  12. branches: scm.branches,
  13. extensions: [
  14. [$class: 'CloneOption', depth: 1, shallow: true, noTags: true],
  15. [$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [
  16. [path: 'docs/jenkins/produ/_shared/'],
  17. ]],
  18. ],
  19. userRemoteConfigs: scm.userRemoteConfigs,
  20. ]
  21. }
  22. pipeline {
  23. agent any
  24. options {
  25. buildDiscarder(logRotator(numToKeepStr: '15'))
  26. timestamps()
  27. timeout(time: 45, unit: 'MINUTES')
  28. }
  29. parameters {
  30. string(name: 'SOURCE_TAG', defaultValue: 'uat-latest', trim: true,
  31. description: 'Harbor UAT tag,默认 uat-latest;回滚填 uat-build-<N>')
  32. string(name: 'TARGET_TAG', defaultValue: '', trim: true,
  33. description: '留空则 produ-${BUILD_NUMBER}')
  34. string(name: 'HARBOR_REGISTRY', defaultValue: '39.105.153.68', trim: true)
  35. string(name: 'HARBOR_PROJECT', defaultValue: 'alien_cloud', trim: true)
  36. choice(name: 'PROMOTE_METHOD', choices: ['harbor-api', 'docker-pull'],
  37. description: 'harbor-api=服务端打 tag(快,默认)')
  38. choice(name: 'DEPLOY_STRATEGY', choices: ['rolling', 'canary', 'skip'],
  39. description: '''rolling=更新 stable Deployment,kubectl 滚动替换 Pod(全量发版)
  40. canary=仅更新 *-canary Deployment,并按 CANARY_WEIGHT 设置 Ingress 灰度流量
  41. skip=只晋升 Harbor 镜像,不执行 kubectl''')
  42. string(name: 'CANARY_WEIGHT', defaultValue: '10', trim: true)
  43. string(name: 'K8S_NAMESPACE', defaultValue: 'alien-produ', trim: true)
  44. booleanParam(name: 'DRY_RUN', defaultValue: false)
  45. }
  46. environment {
  47. HARBOR_CREDENTIALS = 'harbor-robot-alien'
  48. KUBECONFIG_CREDENTIALS = 'ack-kubeconfig-alien'
  49. }
  50. stages {
  51. stage('Promote image & Deploy ACK') {
  52. steps {
  53. script {
  54. sparseCheckoutProduShared()
  55. def k8s = load 'docs/jenkins/produ/_shared/k8s-produ-lib.groovy'
  56. k8s.promoteOneServiceToAck(this, SVC)
  57. echo ">>> gateway 完成: ${env.IMAGE_REF}"
  58. }
  59. }
  60. }
  61. }
  62. }