Jenkinsfile 1.9 KB

123456789101112131415161718192021222324252627282930313233343536
  1. def SVC = [prodDir: 'second', deployName: 'second']
  2. def sparseCheckoutProduShared() {
  3. checkout scm: [$class: 'GitSCM', branches: scm.branches,
  4. extensions: [[$class: 'CloneOption', depth: 1, shallow: true, noTags: true],
  5. [$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'docs/jenkins/produ/_shared/']]]],
  6. userRemoteConfigs: scm.userRemoteConfigs]
  7. }
  8. pipeline {
  9. agent any
  10. options { buildDiscarder(logRotator(numToKeepStr: '15')); timestamps(); timeout(time: 45, unit: 'MINUTES') }
  11. parameters {
  12. string(name: 'SOURCE_TAG', defaultValue: 'uat-latest', trim: true,
  13. description: 'Harbor UAT tag,默认 uat-latest;回滚填 uat-build-<N>')
  14. string(name: 'TARGET_TAG', defaultValue: '', trim: true)
  15. string(name: 'HARBOR_REGISTRY', defaultValue: '39.105.153.68', trim: true)
  16. string(name: 'HARBOR_PROJECT', defaultValue: 'alien_cloud', trim: true)
  17. choice(name: 'DEPLOY_STRATEGY', choices: ['rolling', 'canary', 'skip'],
  18. description: '''rolling=更新 stable Deployment,kubectl 滚动替换 Pod(全量发版)
  19. canary=仅更新 *-canary Deployment,并按 CANARY_WEIGHT 设置 Ingress 灰度流量
  20. skip=只晋升 Harbor 镜像,不执行 kubectl''')
  21. string(name: 'CANARY_WEIGHT', defaultValue: '10', trim: true)
  22. string(name: 'K8S_NAMESPACE', defaultValue: 'alien-produ', trim: true)
  23. booleanParam(name: 'DRY_RUN', defaultValue: false)
  24. }
  25. environment { HARBOR_CREDENTIALS = 'harbor-robot-alien'; KUBECONFIG_CREDENTIALS = 'ack-kubeconfig-alien' }
  26. stages {
  27. stage('Promote image & Deploy ACK') {
  28. steps { script {
  29. sparseCheckoutProduShared()
  30. def k8s = load 'docs/jenkins/produ/_shared/k8s-produ-lib.groovy'
  31. k8s.promoteOneServiceToAck(this, SVC)
  32. echo ">>> second: ${env.IMAGE_REF}"
  33. } }
  34. }
  35. }
  36. }