fix(cicd): 部署 stage 加远程 docker login Harbor
Harbor 私有仓库,cd-target pull 需先登录。withCredentials 传凭证 通过 ssh 执行 docker login(stdin 传密码)。
This commit is contained in:
parent
cb75e7096a
commit
b3d8750816
17
Jenkinsfile
vendored
17
Jenkinsfile
vendored
@ -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()}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user