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

Variable from JSON in Pipeline outputs as temp file name

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Whenever I try to use a parameter from a JSON file I'm only getting the name of the temp file that is copied to the workspace. Here is an example of usage and output:

      configFileProvider([configFile(fileId: 'testFile', variable: 'TESTPARAM')]) {
      bat "echo $env.TESTPARAM"
      }

      The output from this is: 
      C:\jenkins\TrustJenkinsPipeline\workspace@tmp\config4843133872643832765tmp

      I have tried all of the following ways as well:
      bat "echo $TESTPARAM"
      bat "echo ${TESTPARAM}"
      bat "echo ${env.TESTPARAM}"
      bat "echo %TESTPARAM%"
      bat "echo %env.TESTPARAM%"

      All of them either return nothing or the same output as above.

      Here is the contents of 'testFile':
      {
      "TESTPARAM": "testValue"
      }

       

      I do not know if this is a bug or me doing it wrong, but so far I haven't had any luck figuring it out.

        Attachments

          Activity

          Hide
          imod Dominik Bartholdi added a comment - - edited

          I think what you are looking for is:

          unix:

          cat $env.TESTPARAM

          windows:

          type $env.TESTPARAM

           

          echo always shows the value of the env variable

          Show
          imod Dominik Bartholdi added a comment - - edited I think what you are looking for is: unix: cat $env.TESTPARAM windows: type $env.TESTPARAM   echo always shows the value of the env variable
          Hide
          jefff Jeff Fehringer added a comment -

          My example of using echo was just to try and get the variable to print to the console so that I know it's grabbing the variable correctly. I can use the built in environment variables by doing:

          bat 'echo %BUILD_ID%'

          However doing the same with TESTPARAM prints blank. I have no idea why I can't get the parameter out of the JSON file.

          Show
          jefff Jeff Fehringer added a comment - My example of using echo was just to try and get the variable to print to the console so that I know it's grabbing the variable correctly. I can use the built in environment variables by doing: bat 'echo %BUILD_ID%' However doing the same with TESTPARAM prints blank. I have no idea why I can't get the parameter out of the JSON file.
          Hide
          imod Dominik Bartholdi added a comment - - edited

          I think there is a misunderstanding of the plugins functionality...

          All this plugin does, is to copy the configured file to a temporary location and then publish this location as an environment variable - so you can access the file via any other tool you like

          Show
          imod Dominik Bartholdi added a comment - - edited I think there is a misunderstanding of the plugins functionality... All this plugin does, is to copy the configured file to a temporary location and then publish this location as an environment variable - so you can access the file via any other tool you like
          Hide
          jefff Jeff Fehringer added a comment -

          Yes you are correct, I didn't understand what it was doing. I was under the impression the variable defined in the configFileProvider block was a variable inside the file that could be used. Thank you for clarifying!

          Show
          jefff Jeff Fehringer added a comment - Yes you are correct, I didn't understand what it was doing. I was under the impression the variable defined in the configFileProvider block was a variable inside the file that could be used. Thank you for clarifying!

            People

            • Assignee:
              domi Dominik Bartholdi
              Reporter:
              jefff Jeff Fehringer
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: