diff --git a/cicd/jenkins-pipelines/build.groovy b/cicd/jenkins-pipelines/build.groovy index bb1401838..e05347dd3 100644 --- a/cicd/jenkins-pipelines/build.groovy +++ b/cicd/jenkins-pipelines/build.groovy @@ -1,5 +1,7 @@ pipeline { - agent any + agent { + label 'agent1' + } triggers { pollSCM('H/5 * * * *') // Watches the `dev` branch } @@ -7,7 +9,6 @@ pipeline { DOCKERHUB_CREDENTIALS = credentials('nalexx6_docker_pass') DOCKERHUB_USERNAME = "nalexx6" NEXUS_SNAPHOT_URL = 'http://localhost:8081/repository/maven-snapshots' - def ARTIFACT_VERSION = sh(script: "mvn help:evaluate -Dexpression=project.version -q -DforceStdout", returnStdout: true).trim() ARTIFACT_PATH = "target" } @@ -25,14 +26,16 @@ pipeline { } stage('Upload to Nexus') { steps { - sh """ - mvn deploy:deploy-file -DgroupId=org -DartifactId=petclinic -Dversion=${ARTIFACT_VERSION} -Dpackaging=jar -Dfile=./target/petclinic-${ARTIFACT_VERSION}.jar -DrepositoryId=maven-snapshots -Durl=${NEXUS_SNAPHOT_URL} --settings settings.xml - """ + script { + def ARTIFACT_VERSION = sh(script: "./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout", returnStdout: true).trim() + sh """./mvnw deploy:deploy-file -DgroupId=org -DartifactId=petclinic -Dversion=${ARTIFACT_VERSION} -Dpackaging=jar -Dfile=./target/petclinic-${ARTIFACT_VERSION}.jar -DrepositoryId=maven-snapshots -Durl=${NEXUS_SNAPHOT_URL} --settings settings.xml""" + } } } stage('Build Docker Image') { steps { script { + def ARTIFACT_VERSION = sh(script: "./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout", returnStdout: true).trim() sh "DOCKER_BUILDKIT=0 docker build --build-arg ARTIFACT_VERSION=${ARTIFACT_VERSION} --build-arg ARTIFACT_PATH=${ARTIFACT_PATH} -t petclinic:${ARTIFACT_VERSION} ." sh "docker tag petclinic:${ARTIFACT_VERSION} ${DOCKERHUB_USERNAME}/petclinic:${ARTIFACT_VERSION}" sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_CREDENTIALS}" diff --git a/cicd/jenkins-pipelines/deploy.groovy b/cicd/jenkins-pipelines/deploy.groovy index d32fdc5fb..49d50579c 100644 --- a/cicd/jenkins-pipelines/deploy.groovy +++ b/cicd/jenkins-pipelines/deploy.groovy @@ -1,5 +1,7 @@ pipeline { - agent any + agent { + label 'agent1' + } parameters { string(name: 'ARTIFACT_VERSION', description: 'Version of the artifact to deploy') } diff --git a/cicd/jenkins-pipelines/precommit.groovy b/cicd/jenkins-pipelines/precommit.groovy index bc6cf8b37..c6dc526c6 100644 --- a/cicd/jenkins-pipelines/precommit.groovy +++ b/cicd/jenkins-pipelines/precommit.groovy @@ -1,12 +1,14 @@ pipeline { - agent any + agent { + label 'agent1' + } 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' + git url: 'https://github.com/Nalexx06/spring-petclinic.git', branch: 'dev' } } stage('Build & Test') { diff --git a/cicd/jenkins-pipelines/promotion.groovy b/cicd/jenkins-pipelines/promotion.groovy index 133e168c2..591f9b3ec 100644 --- a/cicd/jenkins-pipelines/promotion.groovy +++ b/cicd/jenkins-pipelines/promotion.groovy @@ -1,5 +1,7 @@ pipeline { - agent any + agent { + label 'agent1' + } parameters { string(name: 'SNAPSHOT_VERSION', description: 'Snapshot version to promote') } @@ -26,7 +28,7 @@ pipeline { stage('Promote Artifact to Release') { steps { script { - sh "mvn deploy:deploy-file -DgroupId=org -DartifactId=petclinic -Dversion=${RELEASE_VERSION} -Dpackaging=jar -Dfile=petclinic-${RELEASE_VERSION}.jar -DrepositoryId=maven-releases -Durl=${NEXUS_RELEASE_URL} --settings settings.xml" + sh "./mvnw deploy:deploy-file -DgroupId=org -DartifactId=petclinic -Dversion=${RELEASE_VERSION} -Dpackaging=jar -Dfile=petclinic-${RELEASE_VERSION}.jar -DrepositoryId=maven-releases -Durl=${NEXUS_RELEASE_URL} --settings settings.xml" } } }