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

        1. image-2021-07-02-15-22-21-964.png
          5 kB
          krishna
        2. image-2021-07-02-15-22-44-927.png
          2 kB
          krishna
        3. image-2021-07-02-15-23-18-083.png
          6 kB
          krishna
        4. Test_env.jenkinsfile
          2 kB
          krishna

        Activity

          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 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 .
          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: