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

Enviroment Variables values are not accessable

    XMLWordPrintable

Details

    Description

      I am using the environment variable for printing the build numbes , url, change sets etc.,

      Now they are not print the values

       

      I used the script

      the value printed in the file is :

       

      Console output:

       

       

      Attachments

        Activity

          krishna_1997 krishna created issue -
          krishna_1997 krishna made changes -
          Field Original Value New Value
          Priority Critical [ 2 ] Blocker [ 1 ]

          You filed this issue on the environment-manager-tools-plugin component, i.e. the Parasoft Environment Manager plugin. Which version of the plugin are you using?

          Is the script in a freestyle project or in a pipeline project?

          Are the commands of the script part of the project configuration (in a bat pipeline step, or in a freestyle project), or is the script a separate file? If the script is a file, then I would not expect Jenkins to expand any ${env.BUILD_NUMBER} syntax in it. Instead, you should use syntax specific to the scripting language. In a bat script, that would be %BUILD_NUMBER%.

          kon Kalle Niemitalo added a comment - You filed this issue on the environment-manager-tools-plugin component, i.e. the Parasoft Environment Manager  plugin. Which version of the plugin are you using? Is the script in a freestyle project or in a pipeline project? Are the commands of the script part of the project configuration (in a bat pipeline step, or in a freestyle project), or is the script a separate file? If the script is a file, then I would not expect Jenkins to expand any ${env.BUILD_NUMBER } syntax in it. Instead, you should use syntax specific to the scripting language. In a bat script, that would be %BUILD_NUMBER% .
          krishna_1997 krishna added a comment -

          Hi kon,

          I am using scripted pipeline and I am using Jenkins file and also pipeline script in the configure builds both and also I am using the stages of Linux and windows in a single pipeline

          krishna_1997 krishna added a comment - Hi kon , I am using scripted pipeline and I am using Jenkins file and also pipeline script in the configure builds both and also I am using the stages of Linux and windows in a single pipeline
          kon Kalle Niemitalo added a comment - - edited

          Did you embed the script in Jenkinsfile? Like this

          bat """
          (
          echo "The build number is ${env.BUILD_NUMBER}"
          )>build.txt
          """
          

          Or did you store the script in a separate file, e.g. "script.bat", and then run that from Jenkinsfile like bat ".\\script.bat"?

          kon Kalle Niemitalo added a comment - - edited Did you embed the script in Jenkinsfile? Like this bat """ ( echo "The build number is ${env.BUILD_NUMBER}" )>build.txt """ Or did you store the script in a separate file, e.g. "script.bat", and then run that from Jenkinsfile like bat ".\\script.bat" ?
          krishna_1997 krishna added a comment - - edited

          I have embed the script in the Jenkinsfile

          All bat commands are in the Jenkinsfile

          No individual bat/sh files are used

          krishna_1997 krishna added a comment - - edited I have embed the script in the Jenkinsfile All bat commands are in the Jenkinsfile No individual bat/sh files are used

          Please show exactly how the step is in Jenkinsfile.

          kon Kalle Niemitalo added a comment - Please show exactly how the step is in Jenkinsfile.
          krishna_1997 krishna made changes -
          Attachment Test_env.jenkinsfile [ 57239 ]
          krishna_1997 krishna added a comment -

          I am attaching the Jenkins file here I am also unable to read the parameters given in the email in the post section
          Test_env.jenkinsfile

          krishna_1997 krishna added a comment - I am attaching the Jenkins file here I am also unable to read the parameters given in the email in the post section Test_env.jenkinsfile
          kon Kalle Niemitalo added a comment - - edited

          You use triple apostrophes '''

                                      bat'''
                                          echo "The build number is ${env.BUILD_NUMBER}"
                                          (
                                              echo "The build number is ${env.BUILD_NUMBER}"
                                          )>build.txt
                                          '''
          

          Change them to """ and then it should work.

          See https://groovy-lang.org/syntax.html#_triple_single_quoted_string and https://groovy-lang.org/syntax.html#_triple_double_quoted_string.

          kon Kalle Niemitalo added a comment - - edited You use triple apostrophes ''' bat''' echo "The build number is ${env.BUILD_NUMBER}" ( echo "The build number is ${env.BUILD_NUMBER}" )>build.txt ''' Change them to """ and then it should work. See https://groovy-lang.org/syntax.html#_triple_single_quoted_string and https://groovy-lang.org/syntax.html#_triple_double_quoted_string .
          kon Kalle Niemitalo made changes -
          Resolution Not A Defect [ 7 ]
          Status Open [ 1 ] Resolved [ 5 ]
          kon Kalle Niemitalo made changes -
          Assignee Matt Love [ mattloveparasoft ] Kalle Niemitalo [ kon ]
          kon Kalle Niemitalo made changes -
          Component/s workflow-cps-plugin [ 21713 ]
          Component/s environment-manager-tools-plugin [ 21463 ]
          krishna_1997 krishna added a comment -

          Is there a way to print all the environment variables to a list or dictionary, So we can add to influx as in

          script {
              def my_custom_data = [:]
              my_custom_data["branch"] = env.Branch    // or whatever the env variable is called
              my_custom_data["changeset"] = env.Changeset    // or whatever the env variable is called
              // ...
              influxDbPublisher(selectedTarget: "my-target", customData: my_custom_data)
          }
          
          krishna_1997 krishna added a comment - Is there a way to print all the environment variables to a list or dictionary, So we can add to influx as in script { def my_custom_data = [:] my_custom_data[ "branch" ] = env.Branch // or whatever the env variable is called my_custom_data[ "changeset" ] = env.Changeset // or whatever the env variable is called // ... influxDbPublisher(selectedTarget: "my-target" , customData: my_custom_data) }

          I don't know. The env global variable seems to be implemented in EnvActionImpl.java, where the getProperty method returns the value of the requested environment variable. So it's not a normal Map<String, String>. I don't know whether it is possible to enumerate its keys and values in Groovy. It has the getOverriddenEnvironment method that returns such a map, but it might not be possible to call that method from Groovy.

          kon Kalle Niemitalo added a comment - I don't know. The env global variable seems to be implemented in EnvActionImpl.java , where the getProperty method returns the value of the requested environment variable. So it's not a normal Map<String, String>. I don't know whether it is possible to enumerate its keys and values in Groovy. It has the getOverriddenEnvironment method that returns such a map, but it might not be possible to call that method from Groovy.

          People

            kon Kalle Niemitalo
            krishna_1997 krishna
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: