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

Wrong escaping of environment variables in container Step

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • kubernetes-plugin
    • None

      JENKINS-46278 added environment variables to the container step, allowing e.g. withEnv and withCredentials.

      However, at least double quotes are not correctly escaped:

      podTemplate(name: "horst", label: "label", containers: [
                              containerTemplate(name: 'debian',
                                      image: 'debian',
                                      ttyEnabled: true,
                                      command: 'cat',
                              )
      ]) {
          withEnv(['C="C', 'D=D"',]) {
              node("label") {
                  container('debian') {
                      sh '''echo "C='$C'" '''
                      sh '''echo "D='$D'" '''
                  }
              }
          }
      }
      

      Leads to

      [full] Running shell script
      + echo C='C
      export D=D'
      C='C
      export D=D'
      [Pipeline] sh
      [full] Running shell script
      + echo D=''
      D=''
      

      In a perfect world, kubernetes would implement https://github.com/kubernetes/kubernetes/issues/50321, so no escaping would be needed.

      For now, escaping double quotes in the environment variables will get us at least half the way.

            csanchez Carlos Sanchez
            0x89 Martin Sander
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: