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

Environment variables with '$' have '$$' when used in sh step inside a container step.

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Minor
    • Resolution: Fixed
    • kubernetes-plugin
    • None
    • CloudBees Core 2.222.1.1, Kubernetes plugin 1.25.2
    • 1.28.6

    Description

      Here's a pipeline that reproduces the bug:

       

      podTemplate {
        node(POD_LABEL) {
          container("jnlp") {
            stage("Run") {
              env.FOO = '$string\$with\$dollars'
              echo "from groovy: ${env.FOO}"
              sh 'env | grep FOO'
              sh 'echo from sh: $FOO'
              }
           }
        }
      }
      

      Here's the output:

      from groovy: $string$with$dollars
      FOO=$$string$$with$$dollars
      from sh: $$string$$with$$dollars

      Note that all the dollar signs have been doubled! Note that we've included a call to env, which prints the same incorrect string, so that we can eliminate the possibility of groovy string interpolation issues.

      We isolated the problem to the container() function. The bug does not occur with this version of the code, where it is removed, despite that the exact same container (jnlp) is actually used:

       

      podTemplate {
        node(POD_LABEL) {
          stage("Run") {
            env.FOO = '$string\$with\$dollars'
            echo "from groovy: ${env.FOO}"
            sh 'env | grep FOO'
            sh 'echo from sh: $FOO'
            }
          }
        }
      }
      

       

       

      Attachments

        Issue Links

          Activity

            There are no comments yet on this issue.

            People

              kerogers Kenneth Rogers
              kerogers Kenneth Rogers
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: