Jenkins pipeline running docker

pipeline {
agent { label 'server_61' }

stages {
stage('Checkout') {
steps {
checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: '[email protected]:github.git/']])
}
}

stage('Down Docker') {
steps {
script {
sh 'docker-compose down'
}
}
}

stage('Remove Image') {
steps {
script {
// Check if the Docker image exists and remove it if it does
sh 'docker image ls dashboardpkt_app:latest | grep dashboardpkt_app && docker image rm dockrimg:latest || echo "Image not found, skipping removal"'
}
}
}

stage('Remove Volume') {
steps {
script {
// Check if the Docker volume exists and remove it if it does
sh 'docker volume ls | grep dashboardpkt_build-app && docker volume rm dockervolume || echo "Volume not found, skipping removal"'
}
}
}

stage('Build and Run Docker Compose') {
steps {
script {
sh 'docker-compose up --build -d'
}
}
}
}
}

Tambahan tips kalau jekins tidak bisa jalan karena masalah ssl error

jalankan command ini di vm jenkins

Related: Docker Build Cache Optimization: Cutting CI/CD Pipeline Latency by 80%.

Related: Running github action runner run.sh as services in ubuntu.

ssh-keyscan github.com >> ~/.ssh/known_hosts

Discover more from Susiloharjo

Subscribe to get the latest posts sent to your email.

Discover more from Susiloharjo

Subscribe now to keep reading and get access to the full archive.

Continue reading