-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
ubuntu
jenkins 2.249.3
jdk8
There are 2 questions :
1。 pipeline/freestylejob cannot get empty param value。 2。 pipeline under docker agent can get empty param value。
I define the pipelie with parameter like below
parameters {
string(name: 'ANDROID_PLATFORM', defaultValue: '')
}
in stage i try to print this parameter 'ANDROID_PLATFORM', like below
stage("0.clean ws") {
steps {
sh '''#!/bin/bash
env
'''
}
}
start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value.
in python code i try to get ANDROID_PLATFORM like this
os.environ.get("ANDROID_PLATFORM")
but this return None.I want this return "", an empty string value。
workaround in python maybe work well like this:
os.environ.get("ANDROID_PLATFORM", "")
- relates to
-
JENKINS-65014 Job save removes obligatory <defaultValue> of <hudson.model.StringParameterDefinition>
-
- Resolved
-
[JENKINS-65066] pipeline/freestylejob cannot get empty param value
Description |
Original:
i define the pipe with parameter like below
parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } in stage like stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } if the trigger this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. |
New:
i define the pipe with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } in stage like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} if the trigger this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this os.environ.get("ANDROID_PLATFORM"), but this return None. I want this return "", an empty string value |
Description |
Original:
i define the pipe with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } in stage like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} if the trigger this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this os.environ.get("ANDROID_PLATFORM"), but this return None. I want this return "", an empty string value |
New:
i define the pipe with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} if the trigger this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this os.environ.get("ANDROID_PLATFORM"), but this return None. I want this return "", an empty string value |
Description |
Original:
i define the pipe with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} if the trigger this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this os.environ.get("ANDROID_PLATFORM"), but this return None. I want this return "", an empty string value |
New:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code}, but this return None. I want this return "", an empty string value |
Description |
Original:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code}, but this return None. I want this return "", an empty string value |
New:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code}, but this return None. I want this return "", an empty string value {code:java} private static EnvVars inherit(@NonNull Map<String,String> overrides) { EnvVars m = new EnvVars(EnvVars.masterEnvVars); // at this line there are 68 var m.overrideExpandingAll(overrides); return m; // at this line there are 64 var. } {code} |
Description |
Original:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code}, but this return None. I want this return "", an empty string value {code:java} private static EnvVars inherit(@NonNull Map<String,String> overrides) { EnvVars m = new EnvVars(EnvVars.masterEnvVars); // at this line there are 68 var m.overrideExpandingAll(overrides); return m; // at this line there are 64 var. } {code} |
New:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code}, but this return None. I want this return "", an empty string value {code:java} private static EnvVars inherit(@NonNull Map<String,String> overrides) { EnvVars m = new EnvVars(EnvVars.masterEnvVars); // at this line there are 68 var m.overrideExpandingAll(overrides); // in this line remove the empty string param. return m; // at this line there are 64 var. } {code} |
Summary | Original: pipeline cannot get empty param in sh step | New: pipeline/freestylejob cannot get empty param value |
Description |
Original:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code}, but this return None. I want this return "", an empty string value {code:java} private static EnvVars inherit(@NonNull Map<String,String> overrides) { EnvVars m = new EnvVars(EnvVars.masterEnvVars); // at this line there are 68 var m.overrideExpandingAll(overrides); // in this line remove the empty string param. return m; // at this line there are 64 var. } {code} |
New:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code}, but this return None. I want this return "", an empty string value {code:java} private static EnvVars inherit(@NonNull Map<String,String> overrides) { EnvVars m = new EnvVars(EnvVars.masterEnvVars); // at this line there are 68 var m.overrideExpandingAll(overrides); // in this line remove the empty string param. return m; // at this line there are 64 var. } public void override(String key, String value) { if(value==null || value.length()==0) { // at this line will emove the empty string param. remove(key); return; } int idx = key.indexOf('+'); if(idx>0) { String realKey = key.substring(0,idx); String v = get(realKey); if(v==null) v=value; else { // we might be handling environment variables for a agent that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform==null ? File.pathSeparatorChar : platform.pathSeparator; v=value+ch+v; } put(realKey,v); return; } put(key,value); } {code} |
Description |
Original:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code}, but this return None. I want this return "", an empty string value {code:java} private static EnvVars inherit(@NonNull Map<String,String> overrides) { EnvVars m = new EnvVars(EnvVars.masterEnvVars); // at this line there are 68 var m.overrideExpandingAll(overrides); // in this line remove the empty string param. return m; // at this line there are 64 var. } public void override(String key, String value) { if(value==null || value.length()==0) { // at this line will emove the empty string param. remove(key); return; } int idx = key.indexOf('+'); if(idx>0) { String realKey = key.substring(0,idx); String v = get(realKey); if(v==null) v=value; else { // we might be handling environment variables for a agent that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform==null ? File.pathSeparatorChar : platform.pathSeparator; v=value+ch+v; } put(realKey,v); return; } put(key,value); } {code} |
New:
i define the pipelie with parameter like below
{code:groovy} parameters { string(name: 'ANDROID_PLATFORM', defaultValue: '') } {code} in stage i try to print this parameter 'ANDROID_PLATFORM', like below {code:groovy} stage("0.clean ws") { steps { sh '''#!/bin/bash env ''' } } {code} start this pipeline with empty string ANDROID_PLATFORM, the env command not print this value. in python code i try to get ANDROID_PLATFORM like this{code:groovy} os.environ.get("ANDROID_PLATFORM"){code} but this return None.I want this return "", an empty string value {code:java} private static EnvVars inherit(@NonNull Map<String,String> overrides) { EnvVars m = new EnvVars(EnvVars.masterEnvVars); // at this line there are 68 var m.overrideExpandingAll(overrides); // in this line remove the empty string param. return m; // at this line there are 64 var. } public void override(String key, String value) { if(value==null || value.length()==0) { // at this line will emove the empty string param. remove(key); return; } int idx = key.indexOf('+'); if(idx>0) { String realKey = key.substring(0,idx); String v = get(realKey); if(v==null) v=value; else { // we might be handling environment variables for a agent that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform==null ? File.pathSeparatorChar : platform.pathSeparator; v=value+ch+v; } put(realKey,v); return; } put(key,value); } {code} |
After https://github.com/jenkinsci/jenkins/pull/5275 I suspect this use-case should be considered unsupported in Jenkins. CC jglick timja for an opinion