github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/util/JenkinsEnvironmentRule.groovy (about) 1 package util 2 3 import com.lesfurets.jenkins.unit.BasePipelineTest 4 5 import org.junit.rules.TestRule 6 import org.junit.runner.Description 7 import org.junit.runners.model.Statement 8 9 class JenkinsEnvironmentRule implements TestRule { 10 final BasePipelineTest testInstance 11 12 def env 13 14 JenkinsEnvironmentRule(BasePipelineTest testInstance) { 15 this.testInstance = testInstance 16 } 17 18 @Override 19 Statement apply(Statement base, Description description) { 20 return new Statement() { 21 @Override 22 void evaluate() throws Throwable { 23 env = testInstance.loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment 24 try { 25 testInstance?.nullScript.commonPipelineEnvironment = env 26 } catch (MissingPropertyException e) { 27 //kept for backward compatibility before all tests inherit from BasePiperTest 28 } 29 base.evaluate() 30 } 31 } 32 } 33 }