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

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

    Details

    • Similar Issues:

      Description

      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?

        Attachments

          Issue Links

            Activity

            Hide
            gbois Gregory Boissinot added a comment -

            With this king of value, EnvInject doesn't know if it is a characater or $word is a variable to resolve.
            I suggest you should use an alternate: EnvInject password in the 'Prepare environment' section.
            Could it suit you?

            Show
            gbois Gregory Boissinot added a comment - With this king of value, EnvInject doesn't know if it is a characater or $word is a variable to resolve. I suggest you should use an alternate: EnvInject password in the 'Prepare environment' section. Could it suit you?
            Hide
            singingwolfboy David Baumgold added a comment -

            I can give that a try. However, it doesn't really address the problem: I expect to be able to insert a literal $ by escaping it somehow. In bash, "pas$word" is treated as "pas" followed by the contents of the $word variable, but "pas\$word" is treated as the literal string "pas$word": the backslash escapes the dollar sign. Could EnvInject support escaping in the same way? (In bash, if you want to insert a literal backslash, you have to escape it as well: "a
            b" is treated as the literal string "a\b".)

            Show
            singingwolfboy David Baumgold added a comment - I can give that a try. However, it doesn't really address the problem: I expect to be able to insert a literal $ by escaping it somehow. In bash, "pas$word" is treated as "pas" followed by the contents of the $word variable, but "pas\$word" is treated as the literal string "pas$word": the backslash escapes the dollar sign. Could EnvInject support escaping in the same way? (In bash, if you want to insert a literal backslash, you have to escape it as well: "a b" is treated as the literal string "a\b".)
            Hide
            singingwolfboy David Baumgold added a comment -

            And apparently Jira interprets a double-backslash as a newline. That last sentence should have "a-backslash-backslash-b", not "a-newline-b".

            Show
            singingwolfboy David Baumgold added a comment - And apparently Jira interprets a double-backslash as a newline. That last sentence should have "a-backslash-backslash-b", not "a-newline-b".
            Hide
            singingwolfboy David Baumgold added a comment -

            And apparently Jira interprets a double-backslash as a newline. That last sentence should have "a-backslash-backslash-b", not "a-newline-b".

            Show
            singingwolfboy David Baumgold added a comment - And apparently Jira interprets a double-backslash as a newline. That last sentence should have "a-backslash-backslash-b", not "a-newline-b".
            Hide
            gabrielegiuseppini 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.

            Show
            gabrielegiuseppini 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.
            Hide
            scm_issue_link 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

            Show
            scm_issue_link 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
            Hide
            gbois Gregory Boissinot added a comment -

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

            Show
            gbois Gregory Boissinot added a comment - Escaping with a slash is a good idea. Please upgrade to EnvInject 1.41
            Hide
            alexandrezia 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

            Show
            alexandrezia 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
            Hide
            nickg 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).

            Show
            nickg 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).
            Hide
            nickg Nick Grealy added a comment -

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

            Show
            nickg Nick Grealy added a comment - Can you please check whether this issue is still occurring with recent versions of the plugin?
            Hide
            fayez 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

            Show
            fayez 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
            Hide
            apgray 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?

            Show
            apgray 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?
            Hide
            apgray 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?

            Show
            apgray 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?
            Hide
            wvidana 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

            Show
            wvidana 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

              People

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

                Dates

                • Created:
                  Updated: