Jenkinsfile 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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: 'DEPLOY_STRATEGY', choices: ['rolling', 'canary', 'skip'],
  37. description: 'skip=只推 Harbor,不更新 ACK')
  38. string(name: 'CANARY_WEIGHT', defaultValue: '10', trim: true)
  39. string(name: 'K8S_NAMESPACE', defaultValue: 'alien-produ', trim: true)
  40. booleanParam(name: 'DRY_RUN', defaultValue: false)
  41. }
  42. environment {
  43. HARBOR_CREDENTIALS = 'harbor-robot-alien'
  44. KUBECONFIG_CREDENTIALS = 'ack-kubeconfig-alien'
  45. }
  46. stages {
  47. stage('Promote image & Deploy ACK') {
  48. steps {
  49. script {
  50. sparseCheckoutProduShared()
  51. def k8s = load 'docs/jenkins/produ/_shared/k8s-produ-lib.groovy'
  52. k8s.promoteOneServiceToAck(this, SVC)
  53. echo ">>> gateway 完成: ${env.IMAGE_REF}"
  54. }
  55. }
  56. }
  57. }
  58. }