fix(cicd): 部署 stage 加远程 docker login Harbor

Harbor 私有仓库,cd-target pull 需先登录。withCredentials 传凭证
通过 ssh 执行 docker login(stdin 传密码)。
This commit is contained in:
xiangning 2026-07-17 11:40:38 +08:00
parent cb75e7096a
commit b3d8750816

7
Jenkinsfile vendored
View File

@ -45,13 +45,16 @@ pipeline {
steps { steps {
script { script {
try { try {
withCredentials([usernamePassword(credentialsId: "harbor-credentials", usernameVariable: "HUSER", passwordVariable: "HPASS")]) {
sh """ sh """
ssh -o StrictHostKeyChecking=accept-new ${DEPLOY_HOST} ' ssh -o StrictHostKeyChecking=accept-new ${DEPLOY_HOST} "
echo '${HPASS}' | sudo docker login ${HARBOR} -u ${HUSER} --password-stdin
sudo docker pull ${IMAGE}:latest sudo docker pull ${IMAGE}:latest
sudo docker rm -f buildflow-portal 2>/dev/null || true sudo docker rm -f buildflow-portal 2>/dev/null || true
sudo docker run -d --name buildflow-portal --restart unless-stopped -p ${APP_PORT}:${APP_PORT} ${IMAGE}:latest sudo docker run -d --name buildflow-portal --restart unless-stopped -p ${APP_PORT}:${APP_PORT} ${IMAGE}:latest
' "
""" """
}
echo "部署完成" echo "部署完成"
} catch (e) { } catch (e) {
echo "警告:部署节点 ${DEPLOY_HOST} 暂不可用,跳过自动部署(镜像已推送 Harbor)。原因:${e.getMessage()}" echo "警告:部署节点 ${DEPLOY_HOST} 暂不可用,跳过自动部署(镜像已推送 Harbor)。原因:${e.getMessage()}"