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

Return map of environment variables of job in org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper

    Details

    • Similar Issues:

      Description

      With the Pipeline Plugin, I'd like a list of environment variables to be returned from the build result of a job (like you can already do with `duration` and `description`)

      For example,

      def e = build "test-env"
      echo "${e.environment.GIT_COMMIT}"
      echo "${e.environment.FOO}"
      

      I believe the fix is to add a whitelisted getEnvironment() method to the RunWrapper, similar to the one done in this merged PR here for JENKINS-36306

      The current fix is to access the environment variables is to access it via the rawBuild, however that needs to be explicitly whitelisted as RunWrapper.getRawBuild is blacklisted

      def e = build "test-env"
      echo "${e.rawBuild.environment.GIT_COMMIT}"
      

      Thanks

        Attachments

          Issue Links

            Activity

            Hide
            jglick Jesse Glick added a comment -

            You can already access buildVariables, which works for a downstream Pipeline build, but I guess for a downstream AbstractBuild, the getBuildVariables() method does not include environment variables (whatever the distinction is). Probably simplest to just add environment variables to this map.

            Show
            jglick Jesse Glick added a comment - You can already access buildVariables , which works for a downstream Pipeline build, but I guess for a downstream AbstractBuild , the getBuildVariables() method does not include environment variables (whatever the distinction is). Probably simplest to just add environment variables to this map.
            Hide
            jglick Jesse Glick added a comment -

            Basically this code needs to include both AbstractBuild.getBuildVariables() and AbstractBuild.getEnvironment(NullTaskListener). AFAIK there is no built-in method that provides both. Why there was an ever a distinction in freestyle projects between the two kinds of variables, I have no idea, but users do not really care, they just want all the stuff.

            Show
            jglick Jesse Glick added a comment - Basically this code  needs to include both AbstractBuild.getBuildVariables() and AbstractBuild.getEnvironment(NullTaskListener) . AFAIK there is no built-in method that provides both. Why there was an ever a distinction in freestyle projects between the two kinds of variables, I have no idea, but users do not really care, they just want all the stuff.
            Show
            abayer Andrew Bayer added a comment - PR up at https://github.com/jenkinsci/workflow-support-plugin/pull/45
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pom.xml
            src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java
            src/test/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapperTest.java
            http://jenkins-ci.org/commit/workflow-support-plugin/6f0dc827046a6c237295d1f01cb94f1b40a51e51
            Log:
            [FIXED JENKINS-36528] Include AbstractBuild env vars in buildVariables

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pom.xml src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java src/test/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapperTest.java http://jenkins-ci.org/commit/workflow-support-plugin/6f0dc827046a6c237295d1f01cb94f1b40a51e51 Log: [FIXED JENKINS-36528] Include AbstractBuild env vars in buildVariables
            Hide
            abayer Andrew Bayer added a comment -

            Will be in workflow-support 2.15.

            Show
            abayer Andrew Bayer added a comment - Will be in workflow-support 2.15.
            Hide
            svanoort Sam Van Oort added a comment -

            Released with workflow-support 2.15

            Show
            svanoort Sam Van Oort added a comment - Released with workflow-support 2.15
            Hide
            xuyen Xuyen Tran added a comment -

            I was updated the jenkin-ci-plugin to 2.15. But, still not work for my case. High appreciate for any help.

            Thanks in advanced,

            Xuyen Tran

            Show
            xuyen Xuyen Tran added a comment - I was updated the jenkin-ci-plugin to 2.15. But, still not work for my case. High appreciate for any help. Thanks in advanced, Xuyen Tran

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                cam Cameron I
              • Votes:
                1 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: