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. screenshot-1.png
          screenshot-1.png
          48 kB
        2. NOT_WORKING2.PNG
          NOT_WORKING2.PNG
          4 kB
        3. NOT_WORKING1.PNG
          NOT_WORKING1.PNG
          39 kB

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

          Anudeep Lalam created issue -

          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 made changes -
          Issue Type Original: Bug [ 1 ] New: Improvement [ 4 ]
          Oleg Nenashev made changes -
          Summary Original: Prepare an environment for the run using Properties File is not working in Pipeline New: Pipeline Support: Prepare an environment for the run using Properties File is not working in Pipeline
          Oleg Nenashev made changes -
          Labels New: pipeline

          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
          Oleg Nenashev made changes -
          Epic Link New: JENKINS-42614 [ 179553 ]

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

              Created:
              Updated: