118 lines
4.2 KiB
Groovy
118 lines
4.2 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
parameters {
|
|
string(name: 'SPRING_PROFILES_ACTIVE', defaultValue: 'prod', description: 'Spring Profile (dev/prod)')
|
|
string(name: 'BATCH_DATE', defaultValue: '', description: 'Batch Date (YYYY-MM-DD, empty = today)')
|
|
string(name: 'ADDITIONAL_PARAMS', defaultValue: '', description: 'Additional Parameters (e.g., limit=100)')
|
|
choice(name: 'ACTION', choices: ['RUN', 'VERIFY_ONLY'], description: 'Action to perform')
|
|
}
|
|
|
|
tools {
|
|
jdk 'jdk21'
|
|
}
|
|
|
|
environment {
|
|
BRANCH = 'main'
|
|
GIT_REPO = 'https://kamco.git.gs.dabeeo.com/MVPTeam/kamco-cd-cron.git'
|
|
JAR_NAME = 'generator-dataset-for-training.jar'
|
|
TODAY = sh(script: "date +%Y-%m-%d", returnStdout: true).trim()
|
|
}
|
|
|
|
// NOTE: Pre-built JAR is included in the repository
|
|
// To update the JAR:
|
|
// 1. On a machine with internet, run: ./gradlew clean bootJar
|
|
// 2. Commit the updated build/libs/generator-dataset-for-training.jar
|
|
// 3. Push to repository
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
checkout([
|
|
$class : 'GitSCM',
|
|
branches : [[name: "${env.BRANCH}"]],
|
|
userRemoteConfigs: [[
|
|
url : "${env.GIT_REPO}",
|
|
credentialsId: 'jenkins-dev-token'
|
|
]]
|
|
])
|
|
}
|
|
}
|
|
|
|
|
|
stage('Get Commit Hash') {
|
|
steps {
|
|
script {
|
|
env.COMMIT_HASH = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
|
|
echo "Current commit hash: ${env.COMMIT_HASH}"
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Verify JAR') {
|
|
steps {
|
|
dir("kamco-make-dataset-generation") {
|
|
script {
|
|
def jarPath = "build/libs/${env.JAR_NAME}"
|
|
if (!fileExists(jarPath)) {
|
|
error("JAR file not found: ${jarPath}")
|
|
}
|
|
echo "JAR file verified: ${jarPath}"
|
|
|
|
// Display JAR info
|
|
sh "ls -lh ${jarPath}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Run JAR') {
|
|
when {
|
|
expression { params.ACTION == 'RUN' }
|
|
}
|
|
steps {
|
|
dir("kamco-make-dataset-generation") {
|
|
script {
|
|
def jarPath = "build/libs/${env.JAR_NAME}"
|
|
|
|
// Determine batch date: use parameter if provided, otherwise use today
|
|
def batchDate = params.BATCH_DATE ?: env.TODAY
|
|
|
|
echo "========================================="
|
|
echo "Running JAR: ${jarPath}"
|
|
echo "Profile: ${params.SPRING_PROFILES_ACTIVE}"
|
|
echo "Batch Date: ${batchDate}"
|
|
echo "Additional Params: ${params.ADDITIONAL_PARAMS}"
|
|
echo "========================================="
|
|
|
|
// Build Java command
|
|
def javaCmd = "java -jar ${jarPath}"
|
|
|
|
// Add Spring profile
|
|
if (params.SPRING_PROFILES_ACTIVE) {
|
|
javaCmd += " --spring.profiles.active=${params.SPRING_PROFILES_ACTIVE}"
|
|
}
|
|
|
|
// Add batch date parameter
|
|
javaCmd += " date=${batchDate}"
|
|
|
|
// Add additional parameters
|
|
if (params.ADDITIONAL_PARAMS) {
|
|
javaCmd += " ${params.ADDITIONAL_PARAMS}"
|
|
}
|
|
|
|
echo "Executing: ${javaCmd}"
|
|
|
|
// Execute JAR
|
|
sh """
|
|
${javaCmd}
|
|
"""
|
|
|
|
echo "JAR execution completed successfully"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|