Skip to content

Commit

Permalink
Merge pull request #2 from steveprentice/envVar
Browse files Browse the repository at this point in the history
Add getProperty and setProperty to the env object.
  • Loading branch information
macg33zr authored Sep 5, 2017
2 parents 63aafcb + 0f039c8 commit 4e61950
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pipelineTests/groovy/testSupport/PipelineTestHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@ class PipelineTestHelper extends BasePipelineTest {
*/
binding.setVariable('params', [:])

/**
* Env passed in from Jenkins - may need to override in specific tests
*/
binding.setVariable('env', [BUILD_NUMBER: '1234', PATH: '/some/path'])

/**
* The currentBuild in the job
*/
Expand All @@ -294,6 +289,12 @@ class PipelineTestHelper extends BasePipelineTest {
* PATH
*/
binding.setVariable('PATH', '/some/path')

/**
* Initialize a basic Env passed in from Jenkins - may need to override in specific tests
*/
addEnvVar('BUILD_NUMBER', '1234')
addEnvVar('PATH', '/some/path')
}

/**
Expand Down Expand Up @@ -324,11 +325,10 @@ class PipelineTestHelper extends BasePipelineTest {
* Helper for adding a environment value in tests
*/
void addEnvVar(String name, String val) {
Map env = binding.getVariable('env') as Map
if (env == null) {
env = [:]
binding.setVariable('env', env)
if (!binding.hasVariable('env')) {
binding.setVariable('env', new Expando(getProperty: { p -> this[p] }, setProperty: { p, v -> this[p] = v }))
}
def env = binding.getVariable('env') as Expando
env[name] = val
}
}

0 comments on commit 4e61950

Please sign in to comment.