diff --git a/Jenkinsfile b/Jenkinsfile index d3ce10f..81e2db2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,13 +45,16 @@ pipeline { steps { script { try { - sh """ - ssh -o StrictHostKeyChecking=accept-new ${DEPLOY_HOST} ' - sudo docker pull ${IMAGE}:latest - 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 - ' - """ + withCredentials([usernamePassword(credentialsId: "harbor-credentials", usernameVariable: "HUSER", passwordVariable: "HPASS")]) { + sh """ + ssh -o StrictHostKeyChecking=accept-new ${DEPLOY_HOST} " + echo '${HPASS}' | sudo docker login ${HARBOR} -u ${HUSER} --password-stdin + sudo docker pull ${IMAGE}:latest + 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 + " + """ + } echo "部署完成" } catch (e) { echo "警告:部署节点 ${DEPLOY_HOST} 暂不可用,跳过自动部署(镜像已推送 Harbor)。原因:${e.getMessage()}"