1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/test/groovy/util/JenkinsResetDefaultCacheRule.groovy
Marcus Holl eb57c8df7b
Back commonPipelineEnvironment step by shared class (#821)
* Back commonPipelineEnvironment step by shared class

Each pipeline step comes with its own instance of a commonPipelineEnvironment.
Properties stored on one instance was not shared with the other instances.

Now we strip down the commonPipelineEnvironment step and forward basically
everything to a shared singleton instance.

With that approach all instances of commonPipelineEnvironment shares the
same data and can now be really used for information exchange between the steps.
Before that change only the commonPipelineEnvironment instance associated with
the pipeline script itself could be used for that purpose.

* Remove unneeded commented line
2019-09-26 12:23:36 +02:00

37 lines
999 B
Groovy

package util
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.sap.piper.DefaultValueCache
import com.sap.piper.CommonPipelineEnvironment
class JenkinsResetDefaultCacheRule implements TestRule {
JenkinsResetDefaultCacheRule() {
this(null)
}
//
// Actually not needed. Only provided for the sake of consistency
// with our other rules which comes with an constructor having the
// test case contained in the signature.
JenkinsResetDefaultCacheRule(BasePipelineTest testInstance) {
}
@Override
Statement apply(Statement base, Description description) {
return new Statement() {
@Override
void evaluate() throws Throwable {
DefaultValueCache.reset()
CommonPipelineEnvironment.getInstance().reset()
base.evaluate()
}
}
}
}