diff --git a/JenkinsProba b/JenkinsProba new file mode 100644 index 00000000..8e0b4185 --- /dev/null +++ b/JenkinsProba @@ -0,0 +1,78 @@ +pipeline { + agent any + + +tools { + maven 'Maven 3' // ovo si dodao u Global Tool Configuration + nodejs 'Node 12' // NodeJS koji si tamo dodao + } + + + + stages { + stage('Clone Repo') { + steps { + git branch: 'patch-1', url: 'https://github.com/phk01-afk/angular9-springboot-expensetracker.git' + } + } + + stage('Build Backend') { + steps { + dir('expensetracker') { + sh 'mvn clean install -DskipTests' + } + } + } + + stage('Build Frontend') { + steps { + dir('expense-tracker-fronten') { + sh 'npm install' + sh 'ng build --prod' + } + } + } + + stage('Run Backend') { + steps { + script { + sh "pkill -f '${JAR_NAME}' || true" + sh """ + nohup java -jar ${BACKEND_DIR}/target/${JAR_NAME} \ + --server.port=${BACKEND_PORT} > backend.log 2>&1 & + """ + } + } + } + + stage('Run Frontend (Dev Server)') { + steps { + dir("${FRONTEND_DIR}") { + sh 'nohup npm run start -- --port 4200 > frontend.log 2>&1 &' + } + } + } + + stage('Health Check') { + steps { + script { + sleep 15 + echo "Testing backend on http://localhost:${BACKEND_PORT}/api/v1/expenses" + sh "curl -f http://localhost:${BACKEND_PORT}/api/v1/expenses || exit 1" + + echo "Testing frontend on http://localhost:4200" + sh "curl -f http://localhost:4200 || exit 1" + } + } + } + } + + post { + success { + echo "✅ Backend is running on port ${BACKEND_PORT}, frontend on port 4200" + } + failure { + echo "❌ Pipeline failed. Check backend.log or frontend.log for details." + } + } +} diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..fba771d8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,83 @@ +pipeline { + agent any + + tools { + maven 'Maven 3' + nodejs 'Node 12' + } + + stages { + + stage('Kloniraj Repozitorijum') { + steps { + echo "📥 Kloniram GitHub repozitorijum..." + dir('angular9-springboot-expensetracker') { + deleteDir() + } + git url: 'https://github.com/phk01-afk/angular9-springboot-expensetracker.git', branch: 'patch-1' + } + } + + stage('Build Backend') { + steps { + dir('expensetracker') { + sh 'mvn clean install -Dmaven.test.skip=true -Dmaven.compiler.arguments="--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED"' + } + } + } + + stage('Run Spring Boot') { + steps { + dir('expensetracker') { + sh ''' + echo "✔ Provera .jar fajla:" + ls -l target/*.jar || { echo "❌ JAR fajl nije pronađen!"; exit 1; } + + echo "⚙️ Pokretanje Spring Boot aplikacije..." + pkill -f 'expensetracker-v1.jar' || true + nohup java -jar target/expensetracker-v1.jar > backend.log 2>&1 & + + echo "⏳ Čekam 25 sekundi da se backend startuje..." + sleep 25 + ''' + } + } + } + + stage('Health Check Backend') { + steps { + script { + def retries = 5 + def success = false + while (retries > 0) { + def response = sh(script: "curl -s -o /dev/null -w '%{http_code}' http://localhost:8080/api/v1/expenses", returnStdout: true).trim() + if (response == '200') { + echo "✅ Backend je uspešno startovan!" + success = true + break + } else { + retries-- + echo "⏳ Backend još nije spreman... (${retries} pokušaja ostalo)" + sleep(10) + } + } + if (!success) { + error "❌ Backend health check nije uspeo!" + } + } + } + } + + stage('Build & Serve Frontend') { + steps { + dir('angular9-springboot-expensetracker/expense-tracker-frontend') { + sh 'npm install' + sh 'pkill -f "ng serve" || true' + sh 'nohup npx ng serve --host 0.0.0.0 --port 4200 > frontend.log 2>&1 &' + } + } + } + + } +} + diff --git a/expensetracker/pom.xml b/expensetracker/pom.xml index 77d004d0..d88bae07 100644 --- a/expensetracker/pom.xml +++ b/expensetracker/pom.xml @@ -1,70 +1,90 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.1.RELEASE - - - in.bushansirgur - expensetracker - v1 - expensetracker - Expense tracking application + + 4.0.0 - - 1.8 - 2.6 - + + org.springframework.boot + spring-boot-starter-parent + 2.3.1.RELEASE + + - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - + in.bushansirgur + expensetracker + v1 + expensetracker + Expense tracking application - - org.springframework.boot - spring-boot-devtools - runtime - true - - - mysql - mysql-connector-java - runtime - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - + + 1.8 + 2.6 + - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + mysql + mysql-connector-java + runtime + + + org.projectlombok + lombok + 1.18.38 + provided + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + true + + + + + + diff --git a/expensetracker/src/main/resources/application.properties b/expensetracker/src/main/resources/application.properties index 9be04a93..75ba19a0 100644 --- a/expensetracker/src/main/resources/application.properties +++ b/expensetracker/src/main/resources/application.properties @@ -1,5 +1,18 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/expensetracker?useSSL=false +#Konfiguracija porta za aplikaciju +server.port=8080 +# Podaci za konekciju sa bazom podataka +spring.datasource.url=jdbc:mysql://localhost:3306/expensetracker?useSSL=false&serverTimezone=UTC spring.datasource.username=expensetracker spring.datasource.password=expensetracker +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.jpa.generate-ddl=true \ No newline at end of file +# Hibernate Dialekt za MySQL +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect # Za MySQL 8.x +# spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect # Za MySQL 5.x + +# Postavke za automatsko kreiranje/izmene DDL tabele (update, create, validate, none) +spring.jpa.hibernate.ddl-auto=update # Možeš koristiti: update, create, validate, none + +# Postavke za SQL logovanje (opciono, korisno za debugging) +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true