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
Re-use paramInterceptor in stringInterceptor
  • Loading branch information
Willem Borgesius authored and Willem Borgesius committed Oct 16, 2020
1 parent 19dc388 commit b1fe47b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ abstract class DeclarativePipelineTest extends BasePipelineTest {
GenericPipelineDeclaration.createComponent(DeclarativePipeline, closure).execute(delegate)
}

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

def stringInterceptor = { Map desc->
if (desc) {
// we are in context of paremetes { string(...)}
if (desc.name) {
addParam(desc.name, desc.defaultValue, false)
}
// we are in context of withCredentaials([string()..]) { }
if(desc.variable) {
return desc.variable
def stringInterceptor = { Map param ->
if (param) {
// we are in context of withCredentials([string()..]) { }
if(param.variable) {
return param.variable
} else {
return paramInterceptor(param)
}
}
}
Expand All @@ -45,6 +44,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 paramInterceptor(param)
})
binding.setVariable('credentials', [:])
binding.setVariable('params', [:])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,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 b1fe47b

Please sign in to comment.