robottelo-ci icon indicating copy to clipboard operation
robottelo-ci copied to clipboard

[RFE] Implement a smart teardown for the pipelines

Open rplevka opened this issue 5 years ago • 0 comments

Currently, the pipeline post section executed on failure tries perform several actions (spanning from archiving the artifacts to destroying the domain) not taking into account the stage it failed on.

This usually causes another failures being raised during the teardown itself, making the failure root cause being buried under a lot of unnecessary logs and failure messages.

If we could keep track of the pipeline progress, e.g. by keeping a simple stage number flag, we could use this var during the teardown to identify only the applicable teardown steps.

e.g.

/* this is just a pseudo-code, don't expect it to be functional, it's just to demonstrate the logic */
stage('create vm'){
 recent_stage = 0;
 ..stage code...
}
stage('install katello'){
 recent_stage = 1;
  ..stage code...
}
stage('run tests'){
 recent_stage = 2;
  ..stage code...
}
stage('run something else'){
 recent_stage = 3;
  ..stage code...
}

post {
  failure {
    teardown_steps = ['destroy_vm', 'archive_artifacts', 'something_else'];
    if(recent_stage > 0){
      for(i=teardown_steps.size - recent_stage; i < teardown_steps.size; i++){
        println(teardown_steps.reverse()[i]);
        eval(teardown_steps[-i]);
        }
      } 
    }
  }
}

rplevka avatar Nov 11 '19 14:11 rplevka