Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-65066

pipeline/freestylejob cannot get empty param value

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core
    • 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", "")

          [JENKINS-65066] pipeline/freestylejob cannot get empty param value

          bright.ma created issue -
          bright.ma made changes -
          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




          bright.ma made changes -
          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




          bright.ma made changes -
          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




          bright.ma made changes -
          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}


          bright.ma made changes -
          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}


          bright.ma made changes -
          Summary Original: pipeline cannot get empty param in sh step New: pipeline/freestylejob cannot get empty param value
          bright.ma made changes -
          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}


          bright.ma made changes -
          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}


          Oleg Nenashev added a comment -

          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

          Oleg Nenashev added a comment - 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

            Unassigned Unassigned
            mmh19891113 bright.ma
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: