Files
json-echo/Jenkinsfile
2025-05-27 15:34:51 +03:00

60 lines
2.0 KiB
Groovy

@Library('my-shared-library@main') _
pipeline {
agent {
kubernetes {
yaml k8sPodTemplate('default', true, true)
}
}
stages{
stage('Retrieve Environment Variables') {
steps {
script {
retrieveEnvVars('maven', ['NEXUS_URL', 'NEXUS_PASS'])
retrieveEnvVars('helm', ['KUBERNETES_API', 'KUBERNETES_TOKEN', 'NEXUS_URL'])
retrieveEnvVars('custom-docker', ['NEXUS_DOCKER_URL', 'NEXUS_DOCKER_PASS'])
}
}
}
stage('Check First Pipeline Status') {
steps {
script {
def jobName = "custom-dind-pipeline"
def jobURL = "http://jenkins-server.default.svc.cluster.local:8080/job/${jobName}/api/json"
// Fetch the raw JSON response
def response = sh(script: "curl -s ${jobURL}", returnStdout: true).trim()
// Parse JSON using Groovy's built-in JSON handling
def jsonSlurper = new groovy.json.JsonSlurper()
def jobData = jsonSlurper.parseText(response)
// Extract the first build number to check if the job has run at least once
def firstBuildNumber = jobData.firstBuild?.number
if (firstBuildNumber == null) {
error("Pipeline '${jobName}' has **never** run! Stopping execution.")
}
echo "Pipeline '${jobName}' has executed before. First build number: ${firstBuildNumber}"
}
}
}
stage('Build and Deploy') {
steps {
script {
buildAndDeploy("json-echo", "json-echo-helm-chart", "my-helm-repo", "1.0.0-SNAPSHOT", true, false, 8091)
}
}
}
}
post {
success {
echo 'Build Successful'
}
failure {
echo 'Build Failed'
}
}
}