|
|
@@ -1,8 +1,6 @@
|
|
|
/**
|
|
|
* 整体 / 单服务 / 多选:仅晋升 Harbor 镜像 + 可选 ACK。
|
|
|
* Script Path:docs/jenkins/produ/whole/Jenkinsfile
|
|
|
- *
|
|
|
- * 注意:load / checkout 必须在 agent 的 stage 内执行,禁止在 pipeline 外顶层 load。
|
|
|
*/
|
|
|
def sparseCheckoutProduShared() {
|
|
|
checkout scm: [
|
|
|
@@ -18,7 +16,6 @@ def sparseCheckoutProduShared() {
|
|
|
]
|
|
|
}
|
|
|
|
|
|
-/** 在 node 内稀疏检出并加载共享库(每个 stage 可重复调用) */
|
|
|
def getProduLibs() {
|
|
|
sparseCheckoutProduShared()
|
|
|
def k8s = load 'docs/jenkins/produ/_shared/k8s-produ-lib.groovy'
|
|
|
@@ -31,6 +28,7 @@ pipeline {
|
|
|
options {
|
|
|
buildDiscarder(logRotator(numToKeepStr: '15'))
|
|
|
disableConcurrentBuilds()
|
|
|
+ skipDefaultCheckout(true)
|
|
|
timestamps()
|
|
|
timeout(time: 120, unit: 'MINUTES')
|
|
|
}
|
|
|
@@ -51,6 +49,10 @@ pipeline {
|
|
|
description: 'Harbor UAT tag,默认 uat-latest;回滚填 uat-build-<N>')
|
|
|
string(name: 'TARGET_TAG', defaultValue: '', trim: true,
|
|
|
description: '留空则 produ-${BUILD_NUMBER}')
|
|
|
+ choice(name: 'PROMOTE_METHOD', choices: ['harbor-api', 'docker-pull'],
|
|
|
+ description: 'harbor-api=服务端打 tag(快);docker-pull=拉取再 push(慢,兼容)')
|
|
|
+ booleanParam(name: 'PARALLEL_ACK_DEPLOY', defaultValue: true,
|
|
|
+ description: 'whole/multi 时并行 kubectl rollout(显著缩短 ACK 阶段)')
|
|
|
string(name: 'HARBOR_REGISTRY', defaultValue: '39.105.153.68', trim: true)
|
|
|
string(name: 'HARBOR_PROJECT', defaultValue: 'alien_cloud', trim: true)
|
|
|
choice(name: 'DEPLOY_STRATEGY', choices: ['rolling', 'canary', 'skip'],
|
|
|
@@ -64,56 +66,37 @@ pipeline {
|
|
|
KUBECONFIG_CREDENTIALS = 'ack-kubeconfig-alien'
|
|
|
}
|
|
|
stages {
|
|
|
- stage('Plan') {
|
|
|
+ stage('Promote & Deploy') {
|
|
|
steps {
|
|
|
script {
|
|
|
def (k8s, reg) = getProduLibs()
|
|
|
def services = reg.filterServices(reg.getServiceRegistry(), params)
|
|
|
env.SOURCE_TAG_RESOLVED = k8s.requireSourceTag(this, params.SOURCE_TAG)
|
|
|
- env.PROMOTE_LIST = services*.prodDir.join(',')
|
|
|
env.TARGET_TAG_RESOLVED = k8s.resolveTargetTag(this, params.TARGET_TAG)
|
|
|
+ env.PROMOTE_LIST = services*.prodDir.join(',')
|
|
|
echo ">>> DEPLOY_MODE=${params.DEPLOY_MODE} 服务=${env.PROMOTE_LIST}"
|
|
|
- echo ">>> ${env.SOURCE_TAG_RESOLVED} → ${env.TARGET_TAG_RESOLVED}"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- stage('Promote images') {
|
|
|
- steps {
|
|
|
- script {
|
|
|
- def (k8s, reg) = getProduLibs()
|
|
|
- def services = reg.filterServices(reg.getServiceRegistry(), params)
|
|
|
+ echo ">>> ${env.SOURCE_TAG_RESOLVED} → ${env.TARGET_TAG_RESOLVED} promote=${params.PROMOTE_METHOD}"
|
|
|
+
|
|
|
k8s.promoteHarborImages(this, services, [
|
|
|
harborRegistry: params.HARBOR_REGISTRY,
|
|
|
harborProject: params.HARBOR_PROJECT,
|
|
|
sourceTag: env.SOURCE_TAG_RESOLVED,
|
|
|
targetTag: env.TARGET_TAG_RESOLVED,
|
|
|
harborCredentialsId: env.HARBOR_CREDENTIALS,
|
|
|
+ promoteMethod: params.PROMOTE_METHOD,
|
|
|
dryRun: params.DRY_RUN == true,
|
|
|
])
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- stage('Deploy to ACK') {
|
|
|
- when { expression { return params.DEPLOY_STRATEGY != 'skip' && !params.DRY_RUN } }
|
|
|
- steps {
|
|
|
- script {
|
|
|
- def (k8s, reg) = getProduLibs()
|
|
|
- def services = reg.filterServices(reg.getServiceRegistry(), params)
|
|
|
- def regHost = params.HARBOR_REGISTRY.trim()
|
|
|
- def proj = params.HARBOR_PROJECT.trim()
|
|
|
- def tgtTag = env.TARGET_TAG_RESOLVED
|
|
|
- def strategy = params.DEPLOY_STRATEGY
|
|
|
- services.each { s ->
|
|
|
- def imageRef = "${regHost}/${proj}/${s.prodDir}:${tgtTag}"
|
|
|
- k8s.deployToAck(this, [
|
|
|
+
|
|
|
+ if (params.DEPLOY_STRATEGY != 'skip' && !params.DRY_RUN) {
|
|
|
+ k8s.deployServicesToAck(this, services, [
|
|
|
+ harborRegistry: params.HARBOR_REGISTRY,
|
|
|
+ harborProject: params.HARBOR_PROJECT,
|
|
|
+ targetTag: env.TARGET_TAG_RESOLVED,
|
|
|
+ deployStrategy: params.DEPLOY_STRATEGY,
|
|
|
k8sNamespace: params.K8S_NAMESPACE,
|
|
|
- imageRef: imageRef,
|
|
|
- deployStrategy: strategy == 'canary' ? 'canary' : 'rolling',
|
|
|
- deploymentStable: s.deployName,
|
|
|
- deploymentCanary: "${s.deployName}-canary",
|
|
|
- ingressCanary: "${s.deployName}-canary",
|
|
|
- canaryWeight: (params.CANARY_WEIGHT ?: '10').trim(),
|
|
|
+ canaryWeight: params.CANARY_WEIGHT,
|
|
|
kubeCredentialsId: env.KUBECONFIG_CREDENTIALS,
|
|
|
+ parallelDeploy: params.PARALLEL_ACK_DEPLOY == true,
|
|
|
])
|
|
|
}
|
|
|
}
|