forked from pierront/rock-paper-scissors
Some checks failed
rock-paper-scissors-jenkins/pipeline/head There was a failure building this commit
66 lines
2.1 KiB
Groovy
66 lines
2.1 KiB
Groovy
pipeline {
|
|
agent any
|
|
tools {
|
|
maven 'maven-3.9'
|
|
}
|
|
stages {
|
|
stage('Compilation') {
|
|
steps {
|
|
echo "Compilation du projet..."
|
|
sh 'mvn clean compile'
|
|
}
|
|
}
|
|
stage('Tests') {
|
|
steps {
|
|
echo "Exécution des tests..."
|
|
sh 'mvn test'
|
|
}
|
|
post {
|
|
always {
|
|
// Publier les résultats de tests JUnit dans Jenkins
|
|
junit 'target/surefire-reports/*.xml'
|
|
}
|
|
}
|
|
}
|
|
stage('Packaging') {
|
|
steps {
|
|
echo "Packaging de l'application (sans exécuter les tests)..."
|
|
sh 'mvn package -DskipTests'
|
|
}
|
|
}
|
|
stage('Déploiement') {
|
|
steps {
|
|
sh '''
|
|
echo "=== Déploiement simple sur le port 8081 ==="
|
|
|
|
cd "$WORKSPACE"
|
|
|
|
# 1) Arrêter l'ancienne instance de CE jar (et pas tout java)
|
|
OLD_PIDS=$(pgrep -f "rock-paper-scissors-0.0.1-SNAPSHOT.jar" || true)
|
|
if [ -n "$OLD_PIDS" ]; then
|
|
echo "Arrêt des anciennes instances: $OLD_PIDS"
|
|
kill $OLD_PIDS || true
|
|
sleep 5
|
|
else
|
|
echo "Aucune ancienne instance à arrêter."
|
|
fi
|
|
|
|
# 2) Vérifier que le jar existe
|
|
JAR_FILE=target/rock-paper-scissors-0.0.1-SNAPSHOT.jar
|
|
if [ ! -f "$JAR_FILE" ]; then
|
|
echo "ERREUR : $JAR_FILE introuvable"
|
|
exit 1
|
|
fi
|
|
echo "Jar sélectionné : $JAR_FILE"
|
|
|
|
# 3) Démarrer en arrière-plan, en évitant que Jenkins tue le process
|
|
echo "Démarrage de l'application..."
|
|
JENKINS_NODE_COOKIE=dontKillMe nohup java -jar "$JAR_FILE" --server.port=8081 > app.log 2>&1 &
|
|
|
|
echo "Déploiement terminé (process lancé en arrière-plan)."
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
}
|