jenkins pipelines updated

This commit is contained in:
moleksiienko 2025-01-15 15:27:19 +02:00
parent 6218422a62
commit 44cc836418
4 changed files with 19 additions and 10 deletions

View file

@ -1,5 +1,7 @@
pipeline { pipeline {
agent any agent {
label 'agent1'
}
triggers { triggers {
pollSCM('H/5 * * * *') // Watches the `dev` branch pollSCM('H/5 * * * *') // Watches the `dev` branch
} }
@ -7,7 +9,6 @@ pipeline {
DOCKERHUB_CREDENTIALS = credentials('nalexx6_docker_pass') DOCKERHUB_CREDENTIALS = credentials('nalexx6_docker_pass')
DOCKERHUB_USERNAME = "nalexx6" DOCKERHUB_USERNAME = "nalexx6"
NEXUS_SNAPHOT_URL = 'http://localhost:8081/repository/maven-snapshots' 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" ARTIFACT_PATH = "target"
} }
@ -25,14 +26,16 @@ pipeline {
} }
stage('Upload to Nexus') { stage('Upload to Nexus') {
steps { steps {
sh """ script {
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 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') { stage('Build Docker Image') {
steps { steps {
script { 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_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 tag petclinic:${ARTIFACT_VERSION} ${DOCKERHUB_USERNAME}/petclinic:${ARTIFACT_VERSION}"
sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_CREDENTIALS}" sh "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_CREDENTIALS}"

View file

@ -1,5 +1,7 @@
pipeline { pipeline {
agent any agent {
label 'agent1'
}
parameters { parameters {
string(name: 'ARTIFACT_VERSION', description: 'Version of the artifact to deploy') string(name: 'ARTIFACT_VERSION', description: 'Version of the artifact to deploy')
} }

View file

@ -1,12 +1,14 @@
pipeline { pipeline {
agent any agent {
label 'agent1'
}
triggers { triggers {
pollSCM('H/5 * * * *') // Adjust polling interval as needed pollSCM('H/5 * * * *') // Adjust polling interval as needed
} }
stages { stages {
stage('Checkout Code') { stage('Checkout Code') {
steps { 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') { stage('Build & Test') {

View file

@ -1,5 +1,7 @@
pipeline { pipeline {
agent any agent {
label 'agent1'
}
parameters { parameters {
string(name: 'SNAPSHOT_VERSION', description: 'Snapshot version to promote') string(name: 'SNAPSHOT_VERSION', description: 'Snapshot version to promote')
} }
@ -26,7 +28,7 @@ pipeline {
stage('Promote Artifact to Release') { stage('Promote Artifact to Release') {
steps { steps {
script { 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"
} }
} }
} }