Skip to content

Commit

Permalink
Pass param value maps back so that they can be logged in the callstac…
Browse files Browse the repository at this point in the history
…k for a build step.

Add secret param method
  • Loading branch information
Willem Borgesius authored and Willem1987 committed Jun 7, 2021
1 parent 6d43157 commit 3b3754f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
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)
}
}
}
}
}
}

0 comments on commit 3b3754f

Please sign in to comment.