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

envInject doesn't support loading straight java.util.Properties files

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • envinject-plugin
    • None
    • CentOS Linux release 7.7.1908, Jenkins 2.348, Environment Injector Plugin Version 2.866.v5c0403e3d4df

      Contrary to the resolution of https://issues.jenkins.io/browse/JENKINS-20334, the plugin doesn't always handle correctly straight java.util.Properties file. This shows that it is preprocessing the content of the properties file before loading it as a properties file. This can result in differences when properties files have some character for which java.util.Properties has special handling.

      The plugin should provide, through a checkbox for backward compatibility, a capability to use straight properties file without any pre-processing.

      Example of build steps demonstrating the character differences when a file is read by the envInject-plugin and when it is read by java.util.Properties:

      • Execute system Groovy script:
        File propertyFile = new File('/tmp/data.properties')
        println "Creating properties file ${propertyFile.absolutePath} using Properties.store(...)"
        Properties properties = new Properties()
        properties.setProperty('a', 'sh -c ls --sort=size')
        properties.setProperty('b', 'cmd /c dir C:\\')
        properties.setProperty('c', '`~!@#$%^&*()-_=+[{]}\\|;:\'"/?.>,<')
        properties.each { k, v ->
          println "${k}: ${v}"
        }
        propertyFile.withOutputStream {
          properties.store(it, '')
        }
        return
        
      • Inject environment variables
        /tmp/data.properties
        
      • Execute shell
        Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
        set +x
        echo 'Content of properties file:'
        cat '/tmp/data.properties'
        echo 'Value of properties injected:'
        echo "a: ${a}"
        echo "b: ${b}"
        echo "c: ${c}"
        
      • Execute system Groovy script
        File propertyFile = new File('/tmp/data.properties')
        println "Value of properties loaded from ${propertyFile.absolutePath} using Properties.load():"
        Properties properties = new Properties()
        propertyFile.withInputStream {
          properties.load(it)
        }
        properties.each { k, v ->
          println "${k}: ${v}"
        }
        return
        

      Output:

      Creating properties file /tmp/data.properties using Properties.store(...)
      a: sh -c ls --sort=size
      b: cmd /c dir C:\
      c: `~!@#$%^&*()-_=+[{]}\|;:'"/?.>,<
      [EnvInject] - Injecting environment variables from a build step.
      [EnvInject] - Injecting as environment variables the properties file path '/tmp/data.properties'
      [EnvInject] - Variables injected successfully.
      [workspace] $ /bin/sh -xe /tmp/jenkins14162689093876532933.sh
      + set +x
      Content of properties file:
      #
      #Thu Jun 16 13:12:10 CDT 2022
      a=sh -c ls --sort\=size
      b=cmd /c dir C\:\\
      c=`~\!@\#$%^&*()-_\=+[{]}\\|;\:'"/?.>,<
      Value of properties injected:
      a: sh -c ls --sort\=size
      b: cmd /c dir C:\
      c: `~\!@\#$%^&*()-_\=+[{]}\|;:'"/?.>,<
      Value of properties loaded from /tmp/data.properties using Properties.load():
      a: sh -c ls --sort=size
      b: cmd /c dir C:\
      c: `~!@#$%^&*()-_=+[{]}\|;:'"/?.>,<
      

            Unassigned Unassigned
            georges474 Georges Zwingelstein
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: