Home > Back-end >  Pause Jenkins Job on failure
Pause Jenkins Job on failure

Time:06-28

I have a Jenkins Job TriggerIngestion that triggers an ingestion (in Postgres Table) Job. This TriggerIngestion job is remotely triggered whenever an insertion/update is required on the Postgres table.

I need the updates/insertions to be sequential. Therefore on any job failure, I need to pause the rest of the job-triggers in the build queue. After resolution of the failure, I should be able to resume from the top of the build queue.

This should not impact other jobs running on the same Jenkins Instance. Please help me with the way to do this.

CodePudding user response:

Since you need sequential executions I assume you have disabled parallel Job execution. If that's the case the easiest way to achieve this is by not ending the initial Job. You can simply keep on retrying until the Job is successful, so the consecutive Jobs will never start and remain in the queue. For example, refer to something like the below.

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                script {
                    executeSomething()
                }
            }
        }
    }
}

def executeSomething() {
    def flag = true
    while(flag) {
        try {
        //Add to Postgres
        if success => flag = false
        } catch(Exception e) {
            // Catching All errors
        }
    }
}

You will have to come up with an exit condition for the above Job. I don't think you want to keep on retrying forever.

  • Related