Testing Github webhook cicd.
This commit is contained in:
Vendored
+35
-29
@@ -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" <<EOF
|
||||
APP_IMAGE=$APP_IMAGE
|
||||
EOF
|
||||
|
||||
docker compose -f "$COMPOSE_FILE" --project-directory "$DEPLOY_DIR" up -d --remove-orphans
|
||||
docker compose -f "$COMPOSE_FILE" --project-directory "$DEPLOY_DIR" ps
|
||||
'''
|
||||
}
|
||||
}
|
||||
stage('Debug env') {
|
||||
steps {
|
||||
sh '''
|
||||
echo "BRANCH_NAME=$BRANCH_NAME"
|
||||
echo "GIT_BRANCH=$GIT_BRANCH"
|
||||
git rev-parse --abbrev-ref HEAD || true
|
||||
git rev-parse HEAD
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stage('Deploy') {
|
||||
when {
|
||||
expression { env.GIT_BRANCH == 'origin/main' || env.GIT_BRANCH == 'main' }
|
||||
}
|
||||
steps {
|
||||
sh 'echo "deploying"'
|
||||
sh 'touch /opt/shagram/TEST_WEBHOOK.txt'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user