Update Jenkinsfile
This commit is contained in:
24
Jenkinsfile
vendored
24
Jenkinsfile
vendored
@@ -16,6 +16,30 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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') {
|
stage('Build and Deploy') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
|
|||||||
Reference in New Issue
Block a user