jenkinsfile

This commit is contained in:
Jesse Houldsworth 2025-03-25 12:48:00 -07:00
parent efba1926cc
commit 3f3d898dae

69
Jenkinsfile vendored
View file

@ -1,59 +1,60 @@
pipeline {
agent any
tools {
maven 'maven-3' // your Maven tool label
}
environment {
ARTIFACTORY_URL = 'http://localhost:8081/artifactory'
BUILD_NAME = "spring-petclinic"
BUILD_NUMBER = "${BUILD_ID}"
DOCKER_IMAGE = "localhost:8081/petclinic-docker-dev-local/spring-petclinic:${BUILD_ID}"
JFROG_CLI_BUILD_NAME = "spring-petclinic"
JFROG_CLI_BUILD_NUMBER = "${BUILD_ID}"
}
stages {
stage('Clone Repo') {
stage('Setup JFrog CLI') {
steps {
git branch: 'main', url: 'https://github.com/your-org/your-repo.git'
jfrog rt config --server-id-resolve jfrog-local --server-id-deploy jfrog-local
}
}
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/JesseHouldsworth/spring-petclinic.git'
}
}
stage('Build with Maven') {
steps {
rtMavenRun (
tool: 'maven-3',
pom: 'pom.xml',
goals: 'clean install -DskipTests=true -Denforcer.skip=true',
resolverId: 'maven-resolver',
deployerId: 'maven-deployer'
)
sh '''
jf mvnc --global \
--repo-resolve-releases=libs-release-local \
--repo-resolve-snapshots=libs-snapshot-local
jf mvn clean install -DskipTests=true -Denforcer.skip=true
'''
}
}
stage('Docker Build and Push') {
stage('Build Docker Image') {
steps {
script {
docker.build("${DOCKER_IMAGE}")
def server = Artifactory.server('artifactory-creds')
server.dockerPush(
image: "${DOCKER_IMAGE}",
targetRepo: 'petclinic-docker-dev-local',
buildInfo: Artifactory.newBuildInfo().name("${BUILD_NAME}").number("${BUILD_NUMBER}")
)
}
sh """
docker build -t localhost:8081/petclinic-docker-dev-local/spring-petclinic:${BUILD_ID} .
"""
}
}
stage('Push Docker Image') {
steps {
sh """
jf docker-push \
localhost:8081/petclinic-docker-dev-local/spring-petclinic:${BUILD_ID} \
petclinic-docker-dev-local
"""
}
}
stage('Publish Build Info') {
steps {
script {
def server = Artifactory.server('artifactory-creds')
def buildInfo = Artifactory.newBuildInfo()
buildInfo.name = "${BUILD_NAME}"
buildInfo.number = "${BUILD_NUMBER}"
server.publishBuildInfo(buildInfo)
}
sh '''
jf rt build-collect-env
jf rt build-add-git
jf rt build-publish
'''
}
}
}