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

EnvInject cannot inject variables whose contents contain a dollar sign ($)

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • envinject-plugin
    • None

      If I add an variable in the Jenkins configuration with a dollar sign in the content, then the variable is not injected. The console output says that the variable is unset because it is "unresolved":

      [EnvInject] - Executing scripts and injecting environment variables after the SCM step.
      [EnvInject] - Injecting as environment variables the properties content 
      ADMIN_PASS="pas$word"
      
      [EnvInject] - Variables injected successfully.
      [EnvInject] - Unset unresolved 'ADMIN_PASS' variable.
      

      I've tried single quotes and double quotes, escaping with \$ and with $$, and nothing works: every time, the variable is unset. Help?

          [JENKINS-13157] EnvInject cannot inject variables whose contents contain a dollar sign ($)

          Gabriele Giuseppini added a comment - - edited

          Same here. I have a variable defined as:
          DBName=Jenkins${SVN_REVISION}

          And after upgrading from 1.0 to 1.40, EnvInject stopped creating the new variable.

          Uh, sorry - after reading the latest comments, I need to clarify that I'm trying to get EnvInject to resolve the nested variables, with no luck in 1.40.

          Gabriele Giuseppini added a comment - - edited Same here. I have a variable defined as: DBName=Jenkins${SVN_REVISION} And after upgrading from 1.0 to 1.40, EnvInject stopped creating the new variable. Uh, sorry - after reading the latest comments, I need to clarify that I'm trying to get EnvInject to resolve the nested variables, with no luck in 1.40.

          Code changed in jenkins
          User: Gregory Boissinot
          Path:
          src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java
          http://jenkins-ci.org/commit/envinject-plugin/7cad840a6f897438c855d10b556e142ef8c465a2
          Log:
          Fix JENKINS-13157

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Gregory Boissinot Path: src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java http://jenkins-ci.org/commit/envinject-plugin/7cad840a6f897438c855d10b556e142ef8c465a2 Log: Fix JENKINS-13157

          Escaping with a slash is a good idea.
          Please upgrade to EnvInject 1.41

          Gregory Boissinot added a comment - Escaping with a slash is a good idea. Please upgrade to EnvInject 1.41

          Alexandre Zia added a comment -

          HI,
          I'm using EnvInject Plugin 1.62 hosted at Cloudbees and I'm having exactly this bug:

          [EnvInject] - Variables injected successfully.
          [EnvInject] - Unset unresolved 'APACHE_BASIC_AUTH_PASSWORD' variable.

          The parameter APACHE_BASIC_AUTH_PASSWORD contains a dolalr sign ($) which unfortunately I can't disclose here

          Alexandre Zia added a comment - HI, I'm using EnvInject Plugin 1.62 hosted at Cloudbees and I'm having exactly this bug: [EnvInject] - Variables injected successfully. [EnvInject] - Unset unresolved 'APACHE_BASIC_AUTH_PASSWORD' variable. The parameter APACHE_BASIC_AUTH_PASSWORD contains a dolalr sign ($) which unfortunately I can't disclose here

          Nick Grealy added a comment - - edited

          (Unless I'm mistaken) I couldn't reproduce this issue, using the following versions:

          Jenkins: 1.581
          Environment Injector Plugin: 1.90

          Looking at the code, the correct way to escape a dollar sign character, is by using two dollar sign characters.

          My test:

          Properties Content:
          test1=C:\DOCUME~1\$NCESE~1\LOCALS~1\Temp
          test2=\\127.0.0.1\c$\WINDOWS
          test3=Pas$word
          test4=C:\DOCUME~1\$$NCESE~1\LOCALS~1\Temp
          test5=\\127.0.0.1\c$$\WINDOWS
          test6=Pas$$word

          Windows Command:
          @echo off
          echo %test1%
          echo %test2%
          echo %test3%
          echo %test4%
          echo %test5%
          echo %test6%

          Output:
          C:\DOCUME~1\$NCESE~1\LOCALS~1\Temp
          \\127.0.0.1\c$\WINDOWS
          Pas$word
          C:\DOCUME~1\$NCESE~1\LOCALS~1\Temp
          \\127.0.0.1\c$\WINDOWS
          Pas$word

          Looks correct...

          David Baumgold, can you please advise if this issue is still occurring? (and if so plugin version and steps to reproduce).

          Nick Grealy added a comment - - edited (Unless I'm mistaken) I couldn't reproduce this issue, using the following versions: Jenkins: 1.581 Environment Injector Plugin: 1.90 Looking at the code , the correct way to escape a dollar sign character, is by using two dollar sign characters. My test: Properties Content: test1=C:\DOCUME~1\$NCESE~1\LOCALS~1\Temp test2=\\127.0.0.1\c$\WINDOWS test3=Pas$word test4=C:\DOCUME~1\$$NCESE~1\LOCALS~1\Temp test5=\\127.0.0.1\c$$\WINDOWS test6=Pas$$word Windows Command: @echo off echo %test1% echo %test2% echo %test3% echo %test4% echo %test5% echo %test6% Output: C:\DOCUME~1\$NCESE~1\LOCALS~1\Temp \\127.0.0.1\c$\WINDOWS Pas$word C:\DOCUME~1\$NCESE~1\LOCALS~1\Temp \\127.0.0.1\c$\WINDOWS Pas$word Looks correct... David Baumgold, can you please advise if this issue is still occurring? (and if so plugin version and steps to reproduce).

          Nick Grealy added a comment -

          Can you please check whether this issue is still occurring with recent versions of the plugin?

          Nick Grealy added a comment - Can you please check whether this issue is still occurring with recent versions of the plugin?

          Hello guys,

          I'm using EnvIjnect version : 1.92.1, and I still have the same problem my password is 'AL$$PWS' but when it comes to the output I only get 'AL$PWS'. I've also tried different way to escape none of them work even I tried to put $$$$ but still the output with only one dollar sign.

          Thanks

          Fayez ALSEDLAH added a comment - Hello guys, I'm using EnvIjnect version : 1.92.1, and I still have the same problem my password is 'AL$$PWS' but when it comes to the output I only get 'AL$PWS'. I've also tried different way to escape none of them work even I tried to put $$$$ but still the output with only one dollar sign. Thanks

          Andrew Gray added a comment - - edited

          I am using EnvInject version 1.92.1 and also have the same issue.

          I am trying to set a variable called DRIVE_LETTER="D$"

          How can we properly escape a trailing $ character?

          Andrew Gray added a comment - - edited I am using EnvInject version 1.92.1 and also have the same issue. I am trying to set a variable called DRIVE_LETTER="D$" How can we properly escape a trailing $ character?

          Andrew Gray added a comment -

          Jenkins Core: 2.12
          EnvInject: 1.92.1

          I tried the following evaluated groovy script:

          switch (ENV) {
                  case 'DEV':
          		def map = [WEB_SERVER: '<machine name>.', DB_SERVER: '<machine name>', DRIVE_LETTER: 'D$$']
          		return map
          		break
          	case 'TEST':
          		def map = [WEB_SERVER: '<machine name>', DB_SERVER: '<machine name>', DRIVE_LETTER: 'D$$']
          		return map
          		break
          default:
          		def map = [WEB_SERVER: '', DB_SERVER: '', DRIVE_LETTER: '']
          		return map
          		break
          }
          

          which still didn't work when ENV = 'DEV' or 'TEST'.

          [EnvInject] - Injecting contributions.
          Building in workspace ...
          [EnvInject] - Unset unresolved 'DRIVE_LETTER' variable.
          
          

          If I downgrade to Jenkins Core 2.11 and run the same code I get the same result.

          If I remove the trailing $ from DRIVE_LETTER it works. So that confirms to me that it doesn't like the trailing $ character.

          Can anyone assist with how to escape this $ in this context?

          Andrew Gray added a comment - Jenkins Core: 2.12 EnvInject: 1.92.1 I tried the following evaluated groovy script: switch (ENV) { case 'DEV' : def map = [WEB_SERVER: '<machine name>.' , DB_SERVER: '<machine name>' , DRIVE_LETTER: 'D$$' ] return map break case 'TEST' : def map = [WEB_SERVER: '<machine name>' , DB_SERVER: '<machine name>' , DRIVE_LETTER: 'D$$' ] return map break default : def map = [WEB_SERVER: '', DB_SERVER: ' ', DRIVE_LETTER: ' '] return map break } which still didn't work when ENV = 'DEV' or 'TEST'. [EnvInject] - Injecting contributions. Building in workspace ... [EnvInject] - Unset unresolved 'DRIVE_LETTER' variable. If I downgrade to Jenkins Core 2.11 and run the same code I get the same result. If I remove the trailing $ from DRIVE_LETTER it works. So that confirms to me that it doesn't like the trailing $ character. Can anyone assist with how to escape this $ in this context?

          Wilfrido Vidana added a comment - - edited

          On a linux box this can be solved placing #!/bin/bash at the beggining of the properties file.

          EDIT: not even the bashline works if the options "keep jenkins enrionment variables" and "keep jenkins build variables" are checked. Without them the "$" does pass to the script

          Wilfrido Vidana added a comment - - edited On a linux box this can be solved placing #!/bin/bash at the beggining of the properties file. EDIT: not even the bashline works if the options "keep jenkins enrionment variables" and "keep jenkins build variables" are checked. Without them the "$" does pass to the script

            Unassigned Unassigned
            singingwolfboy David Baumgold
            Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: