Skip to content

Commit f16492d

Browse files
author
Sergei Parshev
committed
MPL-52 Fix for issue with restore of the MPL state after restart (#52)
1 parent 3917527 commit f16492d

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/com/griddynamics/devops/mpl/MPLManager.groovy

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,29 @@
2323

2424
package com.griddynamics.devops.mpl
2525

26+
import com.cloudbees.groovy.cps.NonCPS
27+
28+
import com.griddynamics.devops.mpl.MPLException
29+
import com.griddynamics.devops.mpl.MPLConfig
30+
import com.griddynamics.devops.mpl.Helper
31+
2632
/**
2733
* Object to help with MPL pipelines configuration & poststeps
2834
*
2935
* @author Sergei Parshev <[email protected]>
3036
*/
31-
@Singleton
3237
class MPLManager implements Serializable {
38+
/**
39+
* Simple realization of a singleton
40+
*/
41+
private static inst = null
42+
43+
public static getInstance() {
44+
if( ! inst )
45+
inst = new MPLManager()
46+
return inst
47+
}
48+
3349
/** List of paths which is used to find modules in libraries */
3450
private List modulesLoadPaths = ['com/griddynamics/devops/mpl']
3551

@@ -246,4 +262,22 @@ class MPLManager implements Serializable {
246262
public popActiveModule() {
247263
activeModules.pop()
248264
}
265+
266+
/**
267+
* Restore the static object state if the pipeline was interrupted
268+
*
269+
* This function helps to make sure the MPL object will be restored
270+
* if jenkins was restarted during the pipeline execution. It will
271+
* work if the MPL object is stored in the pipeline:
272+
*
273+
* var/MPLPipeline.groovy:
274+
* ...
275+
* def MPL = MPLPipelineConfig(body, [
276+
* ...
277+
*/
278+
@NonCPS
279+
private void readObject(java.io.ObjectInputStream inp) throws IOException, ClassNotFoundException {
280+
inp.defaultReadObject()
281+
inst = this
282+
}
249283
}

0 commit comments

Comments
 (0)