From 1e1a85bb19c40bb8355f12e92e0c5758530b7c7e Mon Sep 17 00:00:00 2001 From: moleksiienko Date: Mon, 13 Jan 2025 00:32:09 +0200 Subject: [PATCH] groovy checkpoint --- cicd/jenkins-pipelines/build.groovy | 43 +++++++++++++++++++++++++ cicd/jenkins-pipelines/precommit.groovy | 18 +++++++++++ 2 files changed, 61 insertions(+) create mode 100644 cicd/jenkins-pipelines/build.groovy create mode 100644 cicd/jenkins-pipelines/precommit.groovy diff --git a/cicd/jenkins-pipelines/build.groovy b/cicd/jenkins-pipelines/build.groovy new file mode 100644 index 000000000..9d68df64b --- /dev/null +++ b/cicd/jenkins-pipelines/build.groovy @@ -0,0 +1,43 @@ +pipeline { + agent any + triggers { + pollSCM('H/5 * * * *') // Watches the `dev` branch + } + environment { + DOCKERHUB_CREDENTIALS = credentials('nalexx6-dockerhub-pass') + DOCKERHUB_USERNAME = "nalexxgd" + NEXUS_URL = 'localhost:8081' + } + stages { + stage('Checkout Code') { + steps { + git { + url: 'git@github.com:Nalexx06/spring-petclinic.git' + credentialsId: "nalexx06_github_ssh" + branch: 'dev' + } + } + } + stage('Build & Test') { + steps { + sh './mvnw clean verify' + } + } + stage('Upload to Nexus') { + steps { + sh './mvnw deploy -DaltDeploymentRepository=snapshots::default::${NEXUS_URL}' + } + } + stage('Build Docker Image') { + steps { + script { + def version = sh(script: "mvn help:evaluate -Dexpression=project.version -q -DforceStdout", returnStdout: true).trim() + sh "docker build -t petclinic:${version} ." + sh "docker tag petclinic:${version} ${DOCKERHUB_USERNAME}/petclinic:${version}" + sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_CREDENTIALS}" + sh "docker push ${DOCKERHUB_USERNAME}/petclinic:${version}" + } + } + } + } +} diff --git a/cicd/jenkins-pipelines/precommit.groovy b/cicd/jenkins-pipelines/precommit.groovy new file mode 100644 index 000000000..bc6cf8b37 --- /dev/null +++ b/cicd/jenkins-pipelines/precommit.groovy @@ -0,0 +1,18 @@ +pipeline { + agent any + triggers { + pollSCM('H/5 * * * *') // Adjust polling interval as needed + } + stages { + stage('Checkout Code') { + steps { + git url: 'https://github.com/spring-projects/spring-petclinic.git', branch: 'main' + } + } + stage('Build & Test') { + steps { + sh './mvnw clean verify' // Uses Maven Wrapper to build and test + } + } + } +}