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

Pipeline Support: Prepare an environment for the run using Properties File is not working in Pipeline

      Team,

      In Pipeline Projects when I try to use Properties File Path option of Prepare an environment for the run, The environmental variables are not injected. But Properties File Content works. In my requirement I need to use load "Properties File"..Even though the Properties file is already existing, Jenkins is unable to load.. In freestyle I am not getting any issue.

      Can you please look into this.

      Thanks in advance.

        1. NOT_WORKING1.PNG
          NOT_WORKING1.PNG
          39 kB
        2. NOT_WORKING2.PNG
          NOT_WORKING2.PNG
          4 kB
        3. screenshot-1.png
          screenshot-1.png
          48 kB

          [JENKINS-38483] Pipeline Support: Prepare an environment for the run using Properties File is not working in Pipeline

          Oleg Nenashev added a comment -

          Once you specify a file, you need to restart your Jenkins master or slave if you mean "Prepare an environment for the run" from their configuration. Have you tried it?

          Oleg Nenashev added a comment - Once you specify a file, you need to restart your Jenkins master or slave if you mean "Prepare an environment for the run" from their configuration. Have you tried it?

          Anudeep Lalam added a comment -

          oleg_nenashev,

          Thanks for the comment!

          Restarted and checked, It did't worked. However ,I am just wondering how Jenkins restart is related to this. Also, I am executing echo "BRANCHNAME=TEST" > /tmp/tagNames.properties in Script Content (under Prepare an environment for the run), even this is not working. The file is not getting created at all..

          Whatever I am trying here, when I try the same in Freestyle job, it works perfectly.. I need not do restart or anything....

          Am I missing anything here??

          Anudeep Lalam added a comment - oleg_nenashev , Thanks for the comment! Restarted and checked, It did't worked. However ,I am just wondering how Jenkins restart is related to this. Also, I am executing echo "BRANCHNAME=TEST" > /tmp/tagNames.properties in Script Content (under Prepare an environment for the run ), even this is not working. The file is not getting created at all.. Whatever I am trying here, when I try the same in Freestyle job , it works perfectly.. I need not do restart or anything.... Am I missing anything here??

          Alexandre Martel added a comment - - edited

          Doesn't work for me either.

          The solution for now is to use readProperties function (using 'Pipeline Utility Steps' plugins):

          def props = readProperties file: '/tmp/tagNames.properties'
          

          And transfer it to the current node context:

          @NonCPS
          def mapToList(depmap) {
              def dlist = []
              for (entry in depmap) {
                  dlist.add([entry.key, entry.value])
              }
              dlist
          }
          
          node {
             def props = readProperties file: '/tmp/tagNames.properties'
             def envList = []
             for (it2 in mapToList(props)) {
                  def key = it2[0]
                  def val = it2[1]
                  envList << key + "=" + val
              }
              withEnv(envList) {
                  sh 'echo "${BRANCHNAME}"'
              }
          }
          
          

          Alexandre Martel added a comment - - edited Doesn't work for me either. The solution for now is to use readProperties function (using 'Pipeline Utility Steps' plugins): def props = readProperties file: '/tmp/tagNames.properties' And transfer it to the current node context: @NonCPS def mapToList(depmap) { def dlist = [] for (entry in depmap) { dlist.add([entry.key, entry.value]) } dlist } node { def props = readProperties file: '/tmp/tagNames.properties' def envList = [] for (it2 in mapToList(props)) { def key = it2[0] def val = it2[1] envList << key + "=" + val } withEnv(envList) { sh 'echo "${BRANCHNAME}" ' } }

          Oleg Nenashev added a comment -

          Converting it to RFE since EnvInject does not support Pipeline now (and does not claim to do so)

          Oleg Nenashev added a comment - Converting it to RFE since EnvInject does not support Pipeline now (and does not claim to do so)

          Oleg Nenashev added a comment -

          Created an EPIC for it

          Oleg Nenashev added a comment - Created an EPIC for it

          Jesse Glick added a comment -

          You should not use EnvInject for this purpose to begin with. readFile or if necessary use the Pipeline Utility Steps plugin to load a properties file.

          Jesse Glick added a comment - You should not use EnvInject for this purpose to begin with. readFile or if necessary use the Pipeline Utility Steps plugin to load a properties file.

          Sam Van Oort added a comment -

          Reducing priority to reflect that there's a way to do this and the impact is now smaller.

          Sam Van Oort added a comment - Reducing priority to reflect that there's a way to do this and the impact is now smaller.

          github.com/caryyu added a comment - - edited

          This is a global configuration setup:

          My properties file looks like this:
          /secret/secrets.properties

          VERSION = 12
          

          I can 100% ensure there is a this file in my slave node that is managed by the Kubernetes plugin, which means, every trigger will start an entirely new slave node in place

          Here's how my Jenkinsfile looks like:

          pipeline {
              stages {
                  stage("Hello") {
                      steps {
                          sh '''
                              pwd
                              echo "Hello World"
                              ls /secret
                              echo "The latest version is: ${VERSION}"
                          '''
                      }
                  }
              }
          }
          

          conclusion: !!!! the output is nothing !!!

          github.com/caryyu added a comment - - edited This is a global configuration setup: My properties file looks like this: /secret/secrets.properties VERSION = 12 I can 100% ensure there is a this file in my slave node that is managed by the Kubernetes plugin, which means, every trigger will start an entirely new slave node in place Here's how my Jenkinsfile looks like: pipeline { stages { stage( "Hello" ) { steps { sh ''' pwd echo "Hello World" ls /secret echo "The latest version is: ${VERSION}" ''' } } } } conclusion: !!!! the output is nothing !!!

            Unassigned Unassigned
            anudeeplalam Anudeep Lalam
            Votes:
            9 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: