Search code examples
jenkinsgroovy

For builds and deploy we are using Jenkins, build and deploy taking long time at that time GCP token has expire. with that error JWT token issue


For builds and deploy we are using Jenkins, build and deploy taking long time at that time GCP token has expire. with that error JWT token issue[JWT signature expired]with that falied message make it has condition and re run the Deploy job with manage our perameter


Solution

  • I'm not sure where you are getting the error, but simply have a condition in the catch block to check for the specific Error and then trigger the retry. Refer the following sample.

    pipeline {
        agent any
        stages {
        stage("A"){
            steps{
                script {
                    retry(count: 3) {
                            try {
                                // Running stuff here
                                error "JWT signature expired"    
                            } catch(e){
                                echo "${e.getMessage()}"
                                if(e.getMessage().contains("JWT signature expired")) {
                                    // Lets retry, by throwing an error
                                    echo "Retrying!!!!"
                                    error "Just retry"
                                }
                                echo "Not retrying!!!!"
                            }
                        }
                    }
                }
            }
        }
    }