Skip to content

Commit

Permalink
[FIXED JENKINS-43486] Handle non-String parameters in env resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Apr 11, 2017
1 parent 863bcdc commit 153edcf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
Expand Up @@ -60,7 +60,11 @@ public class Environment implements Serializable {

public Map<String,String> getCredsMap(CpsScript script) {
Map<String,String> resolvedMap = new TreeMap<>()
EnvVars contextEnv = new EnvVars((Map<String,String>)script.getProperty("params"))
EnvVars contextEnv = new EnvVars()
((Map<String,Object>)script.getProperty("params")).each { k, v ->
contextEnv.put(k, v.toString())
}

contextEnv.overrideExpandingAll(((EnvActionImpl)script.getProperty("env")).getEnvironment())

credsMap.each { k, v ->
Expand Down Expand Up @@ -112,7 +116,7 @@ public class Environment implements Serializable {
Binding binding = new Binding(alreadySet)

// Also add the params global variable to deal with any references to params.FOO.
binding.setProperty("params", (Map<String, String>) script.getProperty("params"))
binding.setProperty("params", (Map<String, Object>) script.getProperty("params"))

// Do a first round of resolution before we proceed onward to credentials - if no credentials are defined, we
// don't need to do anything more.
Expand Down
Expand Up @@ -141,4 +141,12 @@ public void nonLiteralEnvironment() throws Exception {
.go();
}

@Issue("JENKINS-43486")
@Test
public void booleanParamAndEnv() throws Exception {
expect("booleanParamAndEnv")
.logContains("hello")
.go();
}

}
@@ -0,0 +1,43 @@
/*
* The MIT License
*
* Copyright (c) 2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent none
parameters {
booleanParam(defaultValue: true, description: '', name: 'flag')
}
environment {
FOO = "bar"
}
stages {
stage("foo") {
steps {
echo "hello"
}
}
}
}



0 comments on commit 153edcf

Please sign in to comment.