• Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core

      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);
      

          [JENKINS-35671] Define Run.getEnvironmentForExpansion

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

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

              Created:
              Updated: