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

Environment variable value containing a literal dollar gets an extra dollar prefixed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • kubernetes-plugin
    • None

      Description:

      When using the kubernetes plugin and executing a script inside of a container block, environment variables that contain a literal dollar in their value appear to have an extra dollar added before the existing literal dollar.

      E.g. if the environment and container block were:

      environment {
        FOO="\$BAH"
      }
      steps {
        container('busybox') {
          sh 'echo "FOO=$FOO"'
        }
      }
      

      then the console output shows:

      [Pipeline] withEnv
      [Pipeline] {
      [Pipeline] container
      [Pipeline] {
      [Pipeline] sh
      + echo 'FOO=$$BAH'
      FOO=$$BAH
      [Pipeline] }
      [Pipeline] // container
      [Pipeline] }
      [Pipeline] // withEnv
      

      Expected behaviour:

      the value of the environment variable is not altered when referenced inside the container block.

      Work around:

      None that I've found yet.

      Other info:

      Some other permutations I've tried:

      • When the script is executed outside of the container block, the environment variable value is unchanged.
      • When the value of the environment variable contains a literal dollar not at the start of the string, the value is still changed.  E.g. A value of "Something \$BAH" echoes as "Something $$BAH"

      Environment where the bug was seen:

      Jenkins: CloudBees Core Managed Master 2.204.3.2-rolling
      Kubernetes plugin: 1.23.1

        1. console output.txt
          2 kB
          Paul Woolley
        2. Jenkinsfile
          0.4 kB
          Paul Woolley

            Unassigned Unassigned
            pwoolley Paul Woolley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: