mindboost-rnbo-test-project/Jenkinsfile

71 lines
2.4 KiB
Groovy

pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
checkout([
$class: 'GitSCM',
branches: [[name: 'pipeline/deploy-image']],
userRemoteConfigs: [[
url: 'https://gitea.mindboost.team/Mindboost/mindboost-webapp.git',
credentialsId: 'b5f383be-8c74-40f9-b7e1-3a9c5856df0e'
]]
])
}
}
}
stage('Check Repository') {
steps {
script {
sh 'pwd' // Zeigt das aktuelle Verzeichnis
sh 'ls -la' // Prüft, ob das .git-Verzeichnis existiert
sh 'git status' // Stellt sicher, dass das Repo korrekt initialisiert ist
}
}
}
stage('Get Commit Hash') {
steps {
script {
env.WEBAPP_COMMIT_HASH = sh(
script: 'git rev-parse --short HEAD',
returnStdout: true
).trim()
echo "Commit Hash: ${env.WEBAPP_COMMIT_HASH}"
}
}
}
stage('Check Docker Image with the same tag') {
steps {
script {
def imageExists = sh(
script: "docker images -q mindboost_frontend_image:${env.WEBAPP_COMMIT_HASH} || true",
returnStdout: true
).trim()
if (imageExists) {
echo "Docker Image mit Tag ${env.WEBAPP_COMMIT_HASH} existiert bereits. Überspringe Build."
currentBuild.result = 'SUCCESS'
return
} else {
echo "Kein vorhandenes Docker Image gefunden. Baue neues Image..."
}
}
}
}
stage('Build Docker Image') {
when {
expression { currentBuild.result == null } // Nur wenn vorher kein Image existierte
}
steps {
script {
sh "docker build --build-arg BACKEND_URL=https://b.mindboost.team --rm -t mindboost_frontend_image:${env.WEBAPP_COMMIT_HASH} . "
}
}
}
}
}