forked from jenkinsci/JenkinsPipelineUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for scripted pipeline job with string parameter
- Should demonstrate problem with default com.lesfurets.jenkins.unit.BasePipelineTest.stringInterceptor
- Loading branch information
Reinhold Füreder
committed
Apr 1, 2021
1 parent
6e94552
commit 0858999
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/test/groovy/com/lesfurets/jenkins/TestWithParametersJob.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.lesfurets.jenkins | ||
|
||
import com.lesfurets.jenkins.unit.BaseRegressionTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class TestWithParametersJob extends BaseRegressionTest { | ||
|
||
@Override | ||
@Before | ||
void setUp() throws Exception { | ||
scriptRoots += 'src/test/jenkins' | ||
super.setUp() | ||
} | ||
|
||
@Test | ||
void should_run_script_with_parameters() { | ||
// TODO: Must override default from com/lesfurets/jenkins/unit/BasePipelineTest.groovy:214 | ||
// because com.lesfurets.jenkins.unit.BasePipelineTest.stringInterceptor seems to return null!? | ||
helper.registerAllowedMethod("string", [Map], { Map map -> | ||
return map | ||
}) | ||
|
||
helper.registerAllowedMethod("parameters", [List], { List params -> | ||
params.forEach { param -> | ||
if (param instanceof Map) { | ||
addParam(param.name as String, param.defaultValue, false) | ||
} | ||
} | ||
}) | ||
|
||
// when: | ||
runScript("job/withParameters.jenkins") | ||
|
||
// then: | ||
assertJobStatusSuccess() | ||
testNonRegression("withParameters") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
properties([ | ||
parameters([ | ||
string(name: 'my_param', defaultValue: 'my default value', description: 'My parameter') | ||
]) | ||
]) | ||
|
||
echo("'my_param' value is default: ${params.my_param}") |
5 changes: 5 additions & 0 deletions
5
src/test/resources/callstacks/TestWithParametersJob_withParameters.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
withParameters.run() | ||
withParameters.string({name=my_param, defaultValue=my default value, description=My parameter}) | ||
withParameters.parameters([{name=my_param, defaultValue=my default value, description=My parameter}]) | ||
withParameters.properties([null]) | ||
withParameters.echo('my_param' value is default: my default value) |