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

    XMLWordPrintable

    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

            cam Cameron I created issue -
            cam Cameron I made changes -
            Field Original Value New Value
            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 with `duration` and `description` [already do](https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job))

            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](https://github.com/jenkinsci/workflow-support-plugin/pull/6) 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](https://github.com/jenkinsci/script-security-plugin/pull/69)
            ```
            def e = build "test-env"
            echo "${e.rawBuild.environment.GIT_COMMIT}"
            ```

            Thanks :)
            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 with `duration` and `description` [already do](https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job))

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

            I believe the fix is to add a whitelisted getEnvironment() method to the RunWrapper, similar to the one done in this merged PR [here](https://github.com/jenkinsci/workflow-support-plugin/pull/6) 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](https://github.com/jenkinsci/script-security-plugin/pull/69)
            {code}
            def e = build "test-env"
            echo "${e.rawBuild.environment.GIT_COMMIT}"
            {code}

            Thanks :)
            cam Cameron I made changes -
            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 with `duration` and `description` [already do](https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job))

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

            I believe the fix is to add a whitelisted getEnvironment() method to the RunWrapper, similar to the one done in this merged PR [here](https://github.com/jenkinsci/workflow-support-plugin/pull/6) 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](https://github.com/jenkinsci/script-security-plugin/pull/69)
            {code}
            def e = build "test-env"
            echo "${e.rawBuild.environment.GIT_COMMIT}"
            {code}

            Thanks :)
            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 with `duration` and `description` [already do|https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job])

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

            I believe the fix is to add a whitelisted getEnvironment() method to the RunWrapper, similar to the one done in this merged PR [here|https://github.com/jenkinsci/workflow-support-plugin/pull/6] 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|https://github.com/jenkinsci/script-security-plugin/pull/69]
            {code}
            def e = build "test-env"
            echo "${e.rawBuild.environment.GIT_COMMIT}"
            {code}

            Thanks :)
            cam Cameron I made changes -
            Summary Return list of environment variables of job in org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper Return map of environment variables of job in org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper
            cam Cameron I made changes -
            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 with `duration` and `description` [already do|https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job])

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

            I believe the fix is to add a whitelisted getEnvironment() method to the RunWrapper, similar to the one done in this merged PR [here|https://github.com/jenkinsci/workflow-support-plugin/pull/6] 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|https://github.com/jenkinsci/script-security-plugin/pull/69]
            {code}
            def e = build "test-env"
            echo "${e.rawBuild.environment.GIT_COMMIT}"
            {code}

            Thanks :)
            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|https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job] with `duration` and `description`)

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

            I believe the fix is to add a whitelisted getEnvironment() method to the RunWrapper, similar to the one done in this merged PR [here|https://github.com/jenkinsci/workflow-support-plugin/pull/6] 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|https://github.com/jenkinsci/script-security-plugin/pull/69]
            {code}
            def e = build "test-env"
            echo "${e.rawBuild.environment.GIT_COMMIT}"
            {code}

            Thanks :)
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 173241 ] JNJira + In-Review [ 185015 ]
            abayer Andrew Bayer made changes -
            Component/s pipeline-general [ 21692 ]
            abayer Andrew Bayer made changes -
            Component/s workflow-plugin [ 18820 ]
            jglick Jesse Glick made changes -
            Labels pipeline-build-step-plugin
            jglick Jesse Glick made changes -
            Component/s workflow-support-plugin [ 21719 ]
            Component/s pipeline [ 21692 ]
            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.
            jglick Jesse Glick made changes -
            Link This issue is duplicated by JENKINS-36213 [ JENKINS-36213 ]
            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.
            jglick Jesse Glick made changes -
            Assignee Jesse Glick [ jglick ]
            abayer Andrew Bayer made changes -
            Assignee Andrew Bayer [ abayer ]
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            Show
            abayer Andrew Bayer added a comment - PR up at https://github.com/jenkinsci/workflow-support-plugin/pull/45
            abayer Andrew Bayer made changes -
            Remote Link This issue links to "PR #45 (Web Link)" [ 17675 ]
            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.
            abayer Andrew Bayer made changes -
            Status In Review [ 10005 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            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
            svanoort Sam Van Oort made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            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: