Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM eclipse-temurin:17-jre-alpine

WORKDIR /app

RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring

COPY target/sysfoo-*.jar app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "app.jar"]
1 change: 1 addition & 0 deletions GG
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

150 changes: 150 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
pipeline {
// Alternativa: agent { label 'docker' } — esegue la pipeline su un agent Jenkins con Docker
// installato, utile per gli stage di build/push dell'immagine senza dipendere dal nodo master.
agent any

options {
// Aggiunge il timestamp alle righe della console output della pipeline
timestamps()
/* Tutta la pipeline ha un timeout di 30 minuti */
timeout(time: 30, unit: 'MINUTES')
disableConcurrentBuilds()
}

parameters {
booleanParam(
name: 'SKIP_TESTS',
defaultValue: false,
description: 'Skip unit tests'
)
string(
name: 'DOCKERHUB_USER',
defaultValue: 'marcoz88',
description: 'Username Docker Hub (es. mariorossi → mariorossi/sysfoo)'
)
}

environment {
IMAGE_NAME = "${params.DOCKERHUB_USER}/sysfoo"
}
/* manage jenkins> tools> maven installation> metti stesso nome che usi qua
cioè ( Maven 3.9.6 )
*/
tools{
maven 'Maven 3.9.6'
}
stages {
stage('Checkout') {
steps {
checkout scm // Checkout the source code from the repository
}
}

stage('Start') {
steps {
publishChecks(
name: 'jenkins/ci',
title: 'Jenkins CI',
summary: 'Build avviata da Jenkins.',
status: 'IN_PROGRESS'
)
}
}

stage('Build') {
steps {
// Solo compilazione: fallisce in fretta su errori di sintassi
sh 'mvn clean compile -DskipTests'
}
}

stage('Test') {
when {
expression { return !params.SKIP_TESTS }
}
steps {
timeout(time: 5, unit: 'MINUTES') {
retry(2) {
sh 'mvn test'
}
}
}
post {
always {
// Prova a pubblicare i report JUnit
junit 'target/surefire-reports/*.xml'
}
}
}

stage('Package') {
steps {
// Crea il JAR solo dopo i test (o subito se SKIP_TESTS è attivo)
sh 'mvn package -DskipTests'
}
}

stage('Build Docker Image') {
steps {
sh 'docker build -t $IMAGE_NAME:$BUILD_NUMBER .'
}
}

stage('Push Image') {
steps {
withCredentials([usernamePassword(
credentialsId: 'docker-registry-creds',
usernameVariable: 'USER',
passwordVariable: 'PASS'
)]) {
sh '''
# echo "$PASS" | docker login registry.example.com -u "$USER" --password-stdin
echo "$PASS" | docker login -u "$USER" --password-stdin
docker push $IMAGE_NAME:$BUILD_NUMBER
'''
}
}
}

stage('Deploy') {
steps {
withCredentials([file(credentialsId: 'kubeconfig-docker-desktop', variable: 'KUBECONFIG')]) {
sh '''
kubectl config current-context
kubectl get nodes
kubectl set image deployment/sysfoo sysfoo=$IMAGE_NAME:$BUILD_NUMBER
kubectl rollout status deployment/sysfoo --timeout=120s
'''
}
}
}
}

post {
success {
publishChecks(
name: 'jenkins/ci',
title: 'Jenkins CI',
summary: 'Build completata con successo.',
status: 'COMPLETED',
conclusion: 'SUCCESS',
detailsURL: env.BUILD_URL
)
echo 'Pipeline completata'
}
failure {
publishChecks(
name: 'jenkins/ci',
title: 'Jenkins CI',
summary: 'Build fallita.',
status: 'COMPLETED',
conclusion: 'FAILURE',
detailsURL: env.BUILD_URL
)
echo 'Pipeline fallita'
}
always {
cleanWs()
}
}
}
1 change: 1 addition & 0 deletions ciao
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file added dd
Empty file.
Empty file added dds
Empty file.
1 change: 1 addition & 0 deletions ee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eeee
Empty file added ghgh
Empty file.
Empty file added gu
Empty file.
Empty file added gy
Empty file.
1 change: 1 addition & 0 deletions qq
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file added rrr
Empty file.
Empty file added tt
Empty file.
Empty file added tyty
Empty file.
Empty file added yy
Empty file.