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

Define Run.getEnvironmentForExpansion

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      There is a frequent idiom when making plugins Pipeline-compatible that goes something like

      EnvVars env;
      if (run instanceof AbstractBuild) {
          env = run.getEnvironment(listener);
          env.overrideAll(((AbstractBuild<?,?>) run).getBuildVariables());
      } else {
          env = new EnvVars();
      }
      String whatever = env.expand(this.whatever);
      

      For a traditional build, we wish to allow configuration parameters (for example of a Builder) to be expanded using either the build's global environment, or "build variables" which include parameters, build wrappers, and other stuff. For a Pipeline build, we do not wish to do any expansion whatsoever—the Groovy script should have done any desired expansion before the SimpleBuildStep (for example) even receives its arguments.

      To simplify this idiom, we should:

      • define a method getEnvironmentForExpansion(TaskListener) in Run which by default just delegates to getEnvironment(TaskListener)
      • override it in AbstractBuild to include getBuildVariables()
      • define a method of the same name in WorkflowRun which just returns an empty new EnvVars() (later it can be an @Override)
      • optimize Util.replaceMacro(String, Map) to return its argument immediately if the map is empty
      • search existing plugins for the above idiom and add a TODO comment to simplify them once the baseline is sufficiently new

      The revised code should be something as simple as:

      String whatever = run.getEnvironmentForExpansion(listener).expand(this.whatever);
      

        Attachments

          Issue Links

            Activity

            jglick Jesse Glick created issue -
            jglick Jesse Glick made changes -
            Field Original Value New Value
            Remote Link This issue links to "dev guide section (Web Link)" [ 14449 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 172024 ] JNJira + In-Review [ 184554 ]
            abayer Andrew Bayer made changes -
            Labels api workflow api pipeline workflow
            abayer Andrew Bayer made changes -
            Labels api pipeline workflow api pipeline
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-29144 [ JENKINS-29144 ]

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jglick Jesse Glick
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated: