Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPL] Fixed issues with poststeps execution #5

Merged
merged 1 commit into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
}