Forum Discussion

alpha13m's avatar
alpha13m
Occasional Contributor
4 years ago

jenkins pipeline catch the exit code 0

Hello,

 

I need you're help, i am using Testcomplete 15 and TestExecute 15 with jenkins

With jenkins pipeline

 

 

 

 

 

 

 

 

def RunTest(String TestInfos) {
	try {
		testcompletetest actionOnErrors: 'MAKE_FAILED', 
		actionOnWarnings: 'MAKE_UNSTABLE', 
		credentialsId: 'VEGA-TEST', 
		executorType: 'TE', 
		launchType: 'lcItem', 
		project: 'Macro_Standard_Beta', 
		sessionScreenResolution: '1920x1080', 
		suite: 'Alocpro\\Alocpro.pjs', 
		useTCService: true,
		test: "$TestInfos"
		stageResult = 'SUCCESS'
		echo "< Build SUCESS >"
	} catch (Exception e) {
		catchError(stageResult: 'FAILURE') {
			sh "exit 1"
		}
		echo "< Build Failed >"
    }
}
pipeline {
    agent {
		label 'Srv-Test01'
		
	}
	options {
			timeout(time: 1, unit: 'HOURS') 
			
	}
    stages {
        stage('Reset BDD Beta') {
            steps {
                script{
					RunTest('Beta_02_Reset_BDD')
				}
		    }
        }
        stage('CartesCarburant') {
            steps { 	
				RunTest('Avancee1|Beta_2_01_CartesCarburant1')
			}	
        }       
        stage('Contentieux') {
            steps {
                RunTest('Avancee1|Beta_2_02_Contentieux')
				
		    }
        }
        stage('Contraintes') {
            steps {
                RunTest('Avancee1|Beta_2_03_Contraintes')				
		    }
        }
        /* stage('CRM') {
            steps {
                RunTest('Avancee1|Beta_2_04_CRM')		
		    }
        }
        stage('EtatStatistique') {
            steps {
                RunTest('Avancee1|Beta_2_05_1_EtatStatistique')
		    }
        }*/
        stage('Financement') {
            steps {
                RunTest('Avancee1|Beta_2_06_Financement')
		    }
        }
        stage('Comptabilite') {
            steps {
                RunTest('Avancee1|Beta_2_07_0_Comptabilite')
		    }
        }
        stage('Assurance') {
            steps {
                RunTest('Avancee1|Beta_2_08_Assurance')
		    }
        }
        stage('GestionDesPetroliers') {
            steps {
                RunTest('Avancee1|Beta_2_09_GestionDesPetroliers')
		    }
        }
         stage('Prestation') {
            steps {
                RunTest('Avancee1|Beta_2_10_Prestation')
		    }
        }
    }
    post {
		failure {
			emailext body: '''$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS : \n
			$BUILD_LOG maxLines=8000, escapeHtml=true \n \n Check console output at $BUILD_URL to view the results.''',
            recipientProviders: [brokenBuildSuspects()],
            from: '##',
            subject: 'Build failed in jenkins : $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!',
            to: '##',
            attachLog: true
		}
        unstable {
			emailext body: '''Build unstable - $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS : unstable\n
			$BUILD_LOG maxLines=8000, escapeHtml=true \n \n Check console output at $BUILD_URL to view the results.''',
			recipientProviders: [brokenBuildSuspects()],
			from: '##',
			subject: 'Build instable in jenkins : $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!',
			to: '##',
			attachLog: true
        }
        fixed {
            emailext body: '''$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS : Back to normal !\n
			Check console output at $BUILD_URL to view the results.''',
            recipientProviders: [brokenBuildSuspects()],
            from: '##',
            subject: 'Build back to normal : $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!',
            to: '##'
        }
	}
}

 

 

 

 

 

 

 

 

The jenkinspipeline works, but in my jenkins view i dont have my stage in red when it failed.

 

What i would like to do is to catch the exit code =! 0 and set stageResult = 'FAILURE'

But the other stages needs to continue even if one of them failed there are independent

 

I have tried catchError steps but this is not really what i want.

In this exemple the try catch does nothing even if a test crashed because of the exit code which seems not to be handled in jenkins this way

The error i did in this scenario is in purpose to test the exitcode

 

I have linked a log of the lastest execution i did > logs jenkins.txt

 

Is there a way to catch the exitcode in jenkins?


Thanks

No RepliesBe the first to reply