Skip to content

Commit

Permalink
[MPL] Fixed issues with poststeps execution (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
sparshev authored and pazovtsev committed Jun 19, 2018
1 parent bb1f8fe commit b2f5550
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/com/griddynamics/devops/mpl/MPLManager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class MPLManager implements Serializable {
/** Poststep lists container */
private Map postSteps = [:]

/** Poststeps errors store */
private Map postStepsErrors = [:]

/** Flag to enable enforcement of the modules on project side */
private Boolean enforced = false

Expand Down Expand Up @@ -99,7 +102,7 @@ class MPLManager implements Serializable {
public void postStep(String name, Closure body) {
// TODO: Parallel execution - could be dangerous
if( ! postSteps[name] ) postSteps[name] = []
postSteps[name] << body
postSteps[name] << [module: Helper.activeModules()?.last(), body: body]
}

/**
Expand All @@ -108,8 +111,40 @@ class MPLManager implements Serializable {
* @param name Poststeps list name
*/
public void postStepsRun(String name = 'always') {
postSteps[name]?.reverseEach { it() }
if( postSteps[name] ) {
for( def i = postSteps[name].size()-1; i >= 0 ; i-- ) {
try {
postSteps[name][i]['body']()
}
catch( ex ) {
postStepError(name, postSteps[name][i]['module'], ex)
}
}
}
}

/**
* Post steps could end with errors - and it will be stored to get it later
*
* @param name Poststeps list name
* @param module Name of the module
* @param exception Exception object with error
*/
public void postStepError(String name, String module, Exception exception) {
if( ! postStepsErrors[name] ) postStepsErrors[name] = []
postStepsErrors[name] << [module: module, error: exception]
}

/**
* Get the list of errors become while poststeps execution
*
* @param name Poststeps list name
* @return List of errors
*/
public List getPostStepsErrors(String name) {
postStepsErrors[name] ?: []
}


/**
* Get the modules load paths in reverse order to make sure that defined last will be listed first
Expand Down
3 changes: 3 additions & 0 deletions vars/MPLPostStepsRun.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ import com.griddynamics.devops.mpl.MPLManager
*/
def call(String name) {
MPLManager.instance.postStepsRun(name)
def errors = MPLManager.instance.getPostStepsErrors(name)
for( int e in errors )
println "PostStep '${name}' error: ${e.module}: ${e.error}"
}

0 comments on commit b2f5550

Please sign in to comment.