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

Pass param value maps back #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,20 @@ abstract class DeclarativePipelineTest extends BasePipelineTest {
GenericPipelineDeclaration.createComponent(DeclarativePipeline, closure).execute(delegate)
}

def paramInterceptor = { Map desc ->
addParam(desc.name, desc.defaultValue, false)
}

def stringInterceptor = { Map desc->
if (desc) {
// we are in context of parameters { string(...)}
if (desc.name) {
addParam(desc.name, desc.defaultValue, false)
}
// we are in context of withCredentials([string()..]) { }
if(desc.variable) {
return desc.variable
}
def stringInterceptor = { Map param ->
// we are in context of withCredentials([string()..]) { }
if(param?.variable) {
addParam(param.name, param.defaultValue, false)
return param.variable
} else {
return param
}
}

@Override
void setUp() throws Exception {
super.setUp()
helper.registerAllowedMethod('booleanParam', [Map], paramInterceptor)
helper.registerAllowedMethod('booleanParam', [Map], { booleanParam -> booleanParam })
helper.registerAllowedMethod('checkout', [Closure])
helper.registerAllowedMethod('credentials', [String], { String credName ->
return binding.getVariable('credentials')[credName]
Expand All @@ -47,6 +40,11 @@ abstract class DeclarativePipelineTest extends BasePipelineTest {
helper.registerAllowedMethod('string', [Map], stringInterceptor)
helper.registerAllowedMethod('timeout', [Integer, Closure])
helper.registerAllowedMethod('timestamps')
helper.registerAllowedMethod('password', [Map], { Map param ->
String obscuredValue = param.containsKey("value") ? param.get("value").replaceAll(".","*") : null
param.put("value", obscuredValue)
return param
})
binding.setVariable('credentials', [:])
binding.setVariable('params', [:])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,13 @@ class TestDeclarativePipeline extends DeclarativePipelineTest {
assertJobStatusSuccess()
}

@Test
void should_log_downstream_var() throws Exception {
runScript('DownstreamBuild_Jenkinsfile')
printCallStack()
assertCallStack().contains('build({job=stop, parameters=[{name=stringVarName, value=stringVarValue}, {name=secretVarName, value=***********}, {name=booleanVarName, value=true}], wait=true}')
assertJobStatusSuccess()

}

}
18 changes: 18 additions & 0 deletions src/test/jenkins/jenkinsfiles/DownstreamBuild_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pipeline {
agent none
stages {
stage('Run subbuild') {
parallel {
stage('Build') {
steps {
build(job: "stop", parameters: [
string(name: 'stringVarName', value: 'stringVarValue'),
password(name: 'secretVarName', value: 'superSecret'),
booleanParam(name: 'booleanVarName', value: 'true')
], wait: true)
}
}
}
}
}
}