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

echo step prints null when passed a non-String (was: cannot access envVars from RunWrapper)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • Jenkins 1.609.1
      workflow 1.8

      Hello,

      in Jenkins, I have two jobs:

      • one freestyle named foo, which calls a shell script which does echo $BUILD_ID
      • one workflow job

      When trigerring the job foo from the workflow, it is not possible to get the env vars the build had. For example, if I do

      def foo = build 'foo'
      echo foo.buildVariables
      echo foo.rawBuild.envVars
      

      Then I only get null. However, it is possible, from the script console to get those variables using

      def build = Jenkins.getInstance().getItemByFullName("foo").getBuildByNumber(6)
      build.getEnvVars()
      

      I get

      Result: {BUILD_DISPLAY_NAME=#6, BUILD_ID=6, BUILD_NUMBER=6, BUILD_TAG=jenkins-foo-6, BUILD_URL=http://localhost:8080/job/foo/6/, CLASSPATH=, HUDSON_HOME=/****/jenkins-home, HUDSON_SERVER_COOKIE=****, HUDSON_URL=http://localhost:8080/, JENKINS_HOME=/****/jenkins-home, JENKINS_SERVER_COOKIE=****, JENKINS_URL=http://localhost:8080/, JOB_NAME=foo, JOB_URL=http://localhost:8080/job/foo/, WORKSPACE=/****/jenkins-home/jobs/foo/workspace}
      

      The call to foo.getBuildVariables() return an empty map, but not null, as it is in the workflow.

      The workflow is not sandboxed so the foo.rawBuild is a Run object as in the script console. The two code should return the exact same result, don't you think?

            jglick Jesse Glick
            alecharp Adrien Lecharpentier
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: