code: public String expandAll(Run<?, ?> run, TaskListener listener) throws IOException, InterruptedException {
          if (run instanceof AbstractBuild) {
              try {
                  return TokenMacro.expandAll(
                          (AbstractBuild) run,
                          listener,
                          content,
                          false,
                          Collections.<TokenMacro>emptyList()
                  );
              } catch (MacroEvaluationException e) {
                  LOGGER.error("Can't process token content {} in {} ({})",
                          content, run.getParent().getFullName(), e.getMessage());
                  LOGGER.trace(e.getMessage(), e);
                  return content;
              }
          } else {
              // fallback to env vars only because of token-macro allow only AbstractBuild in 1.11
              return run.getEnvironment(listener).expand(trimToEmpty(content));
          }
      }
docs: Expands all env vars. In case of AbstractBuild also expands token macro and build vars
  
  @param run      build context
  @param listener usually used to log something to console while building env vars
  
  @return string with expanded vars and tokens