From d115624d85eeb92eb7e3581fde619d9fcb03bb48 Mon Sep 17 00:00:00 2001 From: emil28092005 Date: Sun, 18 Jan 2026 05:52:24 +0300 Subject: [PATCH] Testing Github webhook cicd. --- Jenkinsfile | 64 +++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8956fc4..c56c833 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,12 +6,11 @@ pipeline { timestamps() } - environment { - IMAGE_NAME = "shagram" - DEPLOY_DIR = "/opt/shagram/shagram/deploy/shagram" + environment { + IMAGE_NAME = "shagram" + DEPLOY_DIR = "/opt/shagram/shagram/deploy/shagram" COMPOSE_FILE = "${WORKSPACE}/deploy/shagram/compose.yaml" - } - + } stages { stage('Checkout') { @@ -25,6 +24,19 @@ pipeline { } } + stage('Detect branch') { + steps { + script { + + env.GIT_BRANCH = sh( + script: "git name-rev --name-only --refs=refs/remotes/origin/* HEAD | sed 's#^remotes/##' | head -n1", + returnStdout: true + ).trim() + echo "Detected branch: ${env.GIT_BRANCH}" + } + } + } + stage('Build') { steps { script { @@ -39,34 +51,28 @@ pipeline { } stage('Test') { + steps { + sh 'echo "Testing..."' + } + } + + stage('Deploy') { + when { + expression { env.GIT_BRANCH == 'origin/main' } + } steps { sh ''' - echo "Testing..." + set -eux + + mkdir -p "$DEPLOY_DIR" + cat > "$DEPLOY_DIR/.env" <