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

Environment variables with '$' in their content get corrupted in the container step in declerative pipeline

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • kubernetes-plugin
    • None
    • stable/jenkins helm chart: 1.5.9
      jenkins 2.176.2
      kubernets-plugin 1.18.2

      the slaves are: jenkins/jnlp-slave:3.27-1

      Hi,

      I have a declarative pipeline, where the pod contains a few containers, during the execution I want to specify where to run a particular step, so I use the container() step. When I declare an environment variable that contains '$' as value and try to use it in the container step the '$' is doubled.

      I originally noticed this with the credential-binding plugin, but I figured that it can be reproduced with simply using environment variables.

      I've created a simple pipeline to demonstrate:

      pipeline {
          agent any
          environment {
              FRUIT = '$apple'
          }
          stages {
              stage("Test") {
                  steps{
                      sh 'echo "${FRUIT}"'
                      container('jnlp') {
                          sh 'echo "${FRUIT}"'
                      }
                  }
              }
          }
      }
      

      Result:

      [Pipeline] stage
      [Pipeline] { (Test)
      [Pipeline] sh
      + echo $apple
      $apple
      [Pipeline] container
      [Pipeline] {
      [Pipeline] sh
      + echo $$apple
      $$apple
      

       

            Unassigned Unassigned
            netfalo Marcell Lipusz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: