Compare commits

...

4 Commits

21
Jenkinsfile vendored
View File

@@ -1,8 +1,3 @@
def DEPLOY_SSH_CREDENTIAL_ID = env.DEPLOY_SSH_CREDENTIAL_ID ?: 'plesk-agency-deploy-key'
def APP_HOST = env.APP_HOST ?: '192.168.68.89'
def APP_USER = env.APP_USER ?: 'deploy'
def DEPLOY_PATH = env.DEPLOY_PATH ?: '/opt/plesk-agency-portal'
pipeline { pipeline {
// Build + deploy stages require Docker CLI/daemon access on the Jenkins node. // Build + deploy stages require Docker CLI/daemon access on the Jenkins node.
// Ensure this label maps to an agent with Docker installed and usable. // Ensure this label maps to an agent with Docker installed and usable.
@@ -12,6 +7,10 @@ pipeline {
REGISTRY_IMAGE = "plesk-agency-portal" REGISTRY_IMAGE = "plesk-agency-portal"
IMAGE_LATEST = "${REGISTRY_IMAGE}:latest" IMAGE_LATEST = "${REGISTRY_IMAGE}:latest"
IMAGE_BUILD = "${REGISTRY_IMAGE}:build-${BUILD_NUMBER}" IMAGE_BUILD = "${REGISTRY_IMAGE}:build-${BUILD_NUMBER}"
DEPLOY_SSH_CREDENTIAL_ID = "${env.DEPLOY_SSH_CREDENTIAL_ID ?: 'plesk-agency-deploy-key'}"
APP_HOST = "${env.APP_HOST ?: '192.168.68.89'}"
APP_USER = "${env.APP_USER ?: 'deploy'}"
DEPLOY_PATH = "${env.DEPLOY_PATH ?: '/opt/plesk-agency-portal'}"
} }
stages { stages {
@@ -74,10 +73,11 @@ pipeline {
stage('Deploy') { stage('Deploy') {
steps { steps {
withCredentials([sshUserPrivateKey( withCredentials([sshUserPrivateKey(
credentialsId: DEPLOY_SSH_CREDENTIAL_ID, credentialsId: "${env.DEPLOY_SSH_CREDENTIAL_ID}",
keyFileVariable: 'SSH_KEY' keyFileVariable: 'SSH_KEY'
)]) { )]) {
sh ''' sh '''
bash -eo pipefail << 'EOF'
set -euo pipefail set -euo pipefail
rsync -az \ rsync -az \
@@ -93,6 +93,7 @@ pipeline {
"cd $DEPLOY_PATH && chmod +x ./scripts/deploy-prod.sh ./scripts/smoke-check.sh ./scripts/rollback-prod.sh" "cd $DEPLOY_PATH && chmod +x ./scripts/deploy-prod.sh ./scripts/smoke-check.sh ./scripts/rollback-prod.sh"
ssh -i $SSH_KEY $APP_USER@$APP_HOST "cd $DEPLOY_PATH && ./scripts/deploy-prod.sh" ssh -i $SSH_KEY $APP_USER@$APP_HOST "cd $DEPLOY_PATH && ./scripts/deploy-prod.sh"
EOF
''' '''
} }
} }
@@ -100,7 +101,13 @@ pipeline {
stage('Smoke check') { stage('Smoke check') {
steps { steps {
sh 'chmod +x scripts/smoke-check.sh && scripts/smoke-check.sh ${APP_BASE_URL}' sh '''
bash -eo pipefail << EOF
set -euo pipefail
chmod +x scripts/smoke-check.sh
scripts/smoke-check.sh "${APP_BASE_URL}"
EOF
'''
} }
} }
} }