@@ -779,38 +779,41 @@ public class Pipeline implements ResourceRequestor {
779779 this . threadId = Pipeline . rootThreadId
780780 Pipeline . rootPipeline = this
781781
782- // We have to manually add all the external variables to the outer pipeline stage
783- initializeBindingWithExternalVariables(pipelineBuilder)
784-
785- initializeBindingWithGenomes(pipelineBuilder)
786-
787- // Add all the pipeline variables to the external binding
788- this . externalBinding. variables + = pipelineBuilder. binding. variables
789-
790- def cmdlog = CommandLog . cmdLog
791- startDate = new Date ()
792- if (launch) {
793- initializeRunLogs(inputFiles)
794- }
795-
796- Map pipelineStructure = launch ? diagram(host, pipelineBuilder) : null
797-
798- def constructedPipeline = constructPipeline(pipelineBuilder)
799-
800- if (launch) {
801- EventManager . instance. signal(PipelineEvent . STARTED , " Pipeline started" , [pipeline :pipelineStructure])
802- launchPipeline(constructedPipeline, inputFiles, startDate)
803- }
782+ try {
783+ // We have to manually add all the external variables to the outer pipeline stage
784+ initializeBindingWithExternalVariables(pipelineBuilder)
785+
786+ initializeBindingWithGenomes(pipelineBuilder)
787+
788+ // Add all the pipeline variables to the external binding
789+ this . externalBinding. variables + = pipelineBuilder. binding. variables
790+
791+ def cmdlog = CommandLog . cmdLog
792+ startDate = new Date ()
793+ if (launch) {
794+ initializeRunLogs(inputFiles)
795+ }
796+
797+ Map pipelineStructure = launch ? diagram(host, pipelineBuilder) : null
798+
799+ def constructedPipeline = constructPipeline(pipelineBuilder)
800+
801+ if (launch) {
802+ EventManager . instance. signal(PipelineEvent . STARTED , " Pipeline started" , [pipeline :pipelineStructure])
803+ launchPipeline(constructedPipeline, inputFiles, startDate)
804+ }
804805
805- // Make sure the command log ends with newline
806- // as output is not terminated with one by default
807- cmdlog << " "
808-
809- if (! launch) {
810- Pipeline . rootPipeline = previousRootPipeline
806+ // Make sure the command log ends with newline
807+ // as output is not terminated with one by default
808+ cmdlog << " "
809+
810+ return constructedPipeline
811+ }
812+ finally {
813+ if (! launch) {
814+ Pipeline . rootPipeline = previousRootPipeline
815+ }
811816 }
812-
813- return constructedPipeline
814817 }
815818
816819
0 commit comments