Added 12h timeout to all pipelines
Change-Id: I085fcbda322d0877d5ffebd002fc109577788c29
diff --git a/test-groovy-pipeline.groovy b/test-groovy-pipeline.groovy
index 61dfae7..d00d646 100644
--- a/test-groovy-pipeline.groovy
+++ b/test-groovy-pipeline.groovy
@@ -25,61 +25,62 @@
defaultGitUrl = null
}
def checkouted = false
-
-node("docker"){
- try {
- stage("stop old tests"){
- if (gerritRef) {
- def runningTestBuildNums = _getRunningTriggeredTestsBuildNumbers(env["JOB_NAME"], GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER)
- for(int i=0; i<runningTestBuildNums.size(); i++){
- common.infoMsg("Old test with run number ${runningTestBuildNums[i]} found, stopping")
- Jenkins.instance.getItemByFullName(env["JOB_NAME"]).getBuildByNumber(runningTestBuildNums[i]).finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build"));
- }
- }
- }
- stage ('Checkout source code'){
- if (gerritRef) {
- // job is triggered by Gerrit
- checkouted = gerrit.gerritPatchsetCheckout ([
- credentialsId : CREDENTIALS_ID
- ])
- } else if(defaultGitRef && defaultGitUrl) {
- checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
- }
- if(!checkouted){
- throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
- }
- }
- stage ('Run Codenarc tests'){
- if(checkouted){
- def workspace = common.getWorkspace()
- def jenkinsUID = common.getJenkinsUid()
- def jenkinsGID = common.getJenkinsGid()
- def gradle_report = sh (script: "docker run --rm -v ${workspace}:/usr/bin/app:rw -u ${jenkinsUID}:${jenkinsGID} ${GRADLE_IMAGE} ${GRADLE_CMD}", returnStdout: true).trim()
- // Compilation failure doesn't fail the build
- // Check gradle output explicitly
- common.infoMsg(gradle_report)
- if ( gradle_report =~ /Compilation failed/ ) {
- throw new Exception("COMPILATION FAILED!")
+timeout(time: 12, unit: 'HOURS') {
+ node("docker"){
+ try {
+ stage("stop old tests"){
+ if (gerritRef) {
+ def runningTestBuildNums = _getRunningTriggeredTestsBuildNumbers(env["JOB_NAME"], GERRIT_CHANGE_NUMBER, GERRIT_PATCHSET_NUMBER)
+ for(int i=0; i<runningTestBuildNums.size(); i++){
+ common.infoMsg("Old test with run number ${runningTestBuildNums[i]} found, stopping")
+ Jenkins.instance.getItemByFullName(env["JOB_NAME"]).getBuildByNumber(runningTestBuildNums[i]).finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build"));
}
}
- }
-
- } catch (Throwable e) {
- currentBuild.result = 'FAILURE'
- try{
- def errLog = readFile('build/reports/codenarc/main.txt')
- if(errLog){
- common.errorMsg("Error log: ${errLog}")
+ }
+ stage ('Checkout source code'){
+ if (gerritRef) {
+ // job is triggered by Gerrit
+ checkouted = gerrit.gerritPatchsetCheckout ([
+ credentialsId : CREDENTIALS_ID
+ ])
+ } else if(defaultGitRef && defaultGitUrl) {
+ checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
}
- }catch(ex){
- common.errorMsg("Exception occured while reading codenarc output file", ex)
- }
- throw e
- } finally {
- // send notification
- common.sendNotification(currentBuild.result, "" ,["slack"])
- }
+ if(!checkouted){
+ throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
+ }
+ }
+ stage ('Run Codenarc tests'){
+ if(checkouted){
+ def workspace = common.getWorkspace()
+ def jenkinsUID = common.getJenkinsUid()
+ def jenkinsGID = common.getJenkinsGid()
+ def gradle_report = sh (script: "docker run --rm -v ${workspace}:/usr/bin/app:rw -u ${jenkinsUID}:${jenkinsGID} ${GRADLE_IMAGE} ${GRADLE_CMD}", returnStdout: true).trim()
+ // Compilation failure doesn't fail the build
+ // Check gradle output explicitly
+ common.infoMsg(gradle_report)
+ if ( gradle_report =~ /Compilation failed/ ) {
+ throw new Exception("COMPILATION FAILED!")
+ }
+ }
+ }
+
+ } catch (Throwable e) {
+ currentBuild.result = 'FAILURE'
+ try{
+ def errLog = readFile('build/reports/codenarc/main.txt')
+ if(errLog){
+ common.errorMsg("Error log: ${errLog}")
+ }
+ }catch(ex){
+ common.errorMsg("Exception occured while reading codenarc output file", ex)
+ }
+ throw e
+ } finally {
+ // send notification
+ common.sendNotification(currentBuild.result, "" ,["slack"])
+ }
+ }
}
@NonCPS
def _getRunningTriggeredTestsBuildNumbers(jobName, gerritChangeNumber, excludePatchsetNumber){