hudson.model.AbstractBuild.getEnvironment()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中hudson.model.AbstractBuild.getEnvironment()方法的一些代码示例,展示了AbstractBuild.getEnvironment()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractBuild.getEnvironment()方法的具体详情如下:
包路径:hudson.model.AbstractBuild
类名称:AbstractBuild
方法名:getEnvironment

AbstractBuild.getEnvironment介绍

[英]During the build, expose the environments contributed by BuildWrappers and others.

Since 1.444, executor thread that's doing the build can access mutable underlying list, which allows the caller to add/remove environments. The recommended way of adding environment is through BuildWrapper, but this might be handy for build steps who wants to expose additional environment variables to the rest of the build.
[中]在构建过程中,公开buildwrapper和其他人提供的环境。
从1.444开始,执行构建的执行线程可以访问可变的底层列表,这允许调用者添加/删除环境。推荐的添加环境的方法是通过BuildWrapper,但对于希望向构建的其余部分公开其他环境变量的构建步骤来说,这可能很方便。

代码示例

代码示例来源:origin: jenkinsci/jenkins

@Override public final void preCheckout(AbstractBuild build, final Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
  if (runPreCheckout()) {
    final Context c = new Context();
    setUp(c, build, build.getWorkspace(), launcher, listener, build.getEnvironment(listener));
    build.getEnvironments().add(new EnvironmentWrapper(c, launcher));
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Convenient version of {@link #translate(Node, EnvVars, TaskListener)} that just takes a build object in progress.
 * @since 1.460
 */
public ToolInstallation translate(AbstractBuild<?,?> buildInProgress, TaskListener listener) throws IOException, InterruptedException {
  assert buildInProgress.isBuilding();
  return translate(buildInProgress.getBuiltOn(),buildInProgress.getEnvironment(listener),listener);
}

代码示例来源:origin: jenkinsci/jenkins

@Override public final Environment setUp(AbstractBuild build, final Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
  if (runPreCheckout()) {
    return new Environment() {};
  } else {
    final Context c = new Context();
    setUp(c, build, build.getWorkspace(), launcher, listener, build.getEnvironment(listener));
    return new EnvironmentWrapper(c, launcher);
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override public final void preCheckout(AbstractBuild build, final Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
  if (runPreCheckout()) {
    final Context c = new Context();
    setUp(c, build, build.getWorkspace(), launcher, listener, build.getEnvironment(listener));
    build.getEnvironments().add(new EnvironmentWrapper(c, launcher));
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) {
  if (StringUtils.isEmpty(path)) {
    return null;
  }
  try {
    EnvVars env = build.getEnvironment(listener);
    String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver());
    targetPath = env.expand(targetPath);
    if (IOUtils.isAbsolute(targetPath)) {
      return new FilePath(new File(targetPath));
    } else {
      FilePath mrSettings = build.getModuleRoot().child(targetPath);
      FilePath wsSettings = build.getWorkspace().child(targetPath);
      try {
        if (!wsSettings.exists() && mrSettings.exists()) {
          wsSettings = mrSettings;
        }
      } catch (Exception e) {
        throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote());
      }
      return wsSettings;
    }
  } catch (Exception e) {
    throw new IllegalStateException("failed to prepare global settings.xml");
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) {
  if (StringUtils.isEmpty(path)) {
    return null;
  }
  try {
    EnvVars env = build.getEnvironment(listener);
    String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver());
    targetPath = env.expand(targetPath);
    if (IOUtils.isAbsolute(targetPath)) {
      return new FilePath(new File(targetPath));
    } else {
      FilePath mrSettings = build.getModuleRoot().child(targetPath);
      FilePath wsSettings = build.getWorkspace().child(targetPath);
      try {
        if (!wsSettings.exists() && mrSettings.exists()) {
          wsSettings = mrSettings;
        }
      } catch (Exception e) {
        throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote());
      }
      return wsSettings;
    }
  } catch (Exception e) {
    throw new IllegalStateException("failed to prepare settings.xml");
  }
}

代码示例来源:origin: jenkinsci/jenkins

EnvVars envVars = build.getEnvironment(listener);

代码示例来源:origin: jenkinsci/jenkins

VariableResolver<String> vr = build.getBuildVariableResolver();
EnvVars env = build.getEnvironment(listener);

代码示例来源:origin: stackoverflow.com

@Override
public boolean perform(AbstractBuild build, Launcher launcher,
 BuildListener listener) throws IOException, InterruptedException {
  ...
  final EnvVars env = build.getEnvironment(listener);
  String expandedDbUrl = env.expand(dbUrl);
  ...
}

代码示例来源:origin: hudson.plugins/project-inheritance

public static Map<String, String> getEnvFor(AbstractBuild<?, ?> build, TaskListener log) {
  Map<String, String> evMap = new HashMap<String, String>();
  evMap.putAll(build.getBuildVariables());
  try {
    evMap.putAll(build.getEnvironment(log));
  } catch (IOException e) {
    //Do nothing
  } catch (InterruptedException e) {
    //Do nothing
  }
  return evMap;
}

代码示例来源:origin: org.jenkins-ci.plugins/publish-over

private TreeMap<String, String> getEnvironmentVariables(final AbstractBuild<?, ?> build, final TaskListener listener) {
  try {
    final TreeMap<String, String> env = build.getEnvironment(listener);
    env.putAll(build.getBuildVariables());
    return env;
  } catch (Exception e) {
    throw new RuntimeException(Messages.exception_failedToGetEnvVars(), e);
  }
}

代码示例来源:origin: org.hudsonci.plugins/parameterized-trigger

/**
 * Retrieve the build environment from the upstream build
 */
public EnvVars getEnvironment(AbstractBuild<?,?> build, TaskListener listener)
    throws IOException, InterruptedException {
  CapturedEnvironmentAction capture = build.getAction(CapturedEnvironmentAction.class);
  if (capture != null) {
    return capture.getCapturedEnvironment();
  } else {
    return build.getEnvironment(listener);
  }
}

代码示例来源:origin: jenkinsci/debian-package-builder-plugin

private DebianPackageRepo getRepo(AbstractBuild<?, ?> build, Runner runner) throws IOException, InterruptedException {
  String expandedRepo = build.getEnvironment(runner.getListener()).expand(repoId);
  for(DebianPackageRepo repo: getDescriptor().getRepositories()) {
    if (repo.getName().equals(expandedRepo)) {
      return repo;
    }
  }
  throw new IllegalArgumentException(MessageFormat.format("Repo {0} is not found in global configuration", expandedRepo));
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Convenient version of {@link #translate(Node, EnvVars, TaskListener)} that just takes a build object in progress.
 * @since 1.460
 */
public ToolInstallation translate(AbstractBuild<?,?> buildInProgress, TaskListener listener) throws IOException, InterruptedException {
  assert buildInProgress.isBuilding();
  return translate(buildInProgress.getBuiltOn(),buildInProgress.getEnvironment(listener),listener);
}

代码示例来源:origin: jenkinsci/docker-custom-build-environment-plugin

public Docker(DockerServerEndpoint dockerHost, String dockerInstallation, String credentialsId, AbstractBuild build, Launcher launcher, TaskListener listener, boolean verbose, boolean privileged) throws IOException, InterruptedException {
  this.dockerHost = dockerHost;
  this.dockerExecutable = DockerTool.getExecutable(dockerInstallation, Computer.currentComputer().getNode(), listener, build.getEnvironment(listener));
  this.registryEndpoint = new DockerRegistryEndpoint(null, credentialsId);
  this.launcher = launcher;
  this.listener = listener;
  this.build = build;
  this.verbose = verbose | debug;
  this.privileged = privileged;
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
  throws IOException, InterruptedException {
  if (debug) {
    listener.getLogger().println("Running mailer");
  }
  // substitute build parameters
  EnvVars env = build.getEnvironment(listener);
  String recip = env.expand(recipients);
  return new MailSender(recip, dontNotifyEveryUnstableBuild, sendToIndividuals,
    descriptor().getCharset()).execute(build, listener);
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
    throws IOException, InterruptedException {
  if (debug) {
    listener.getLogger().println("Running mailer");
  }
  // substitute build parameters
  EnvVars env = build.getEnvironment(listener);
  String recip = env.expand(recipients);
  return new MailSender(recip, dontNotifyEveryUnstableBuild, sendToIndividuals,
      descriptor().getCharset()).execute(build, listener);
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
  throws IOException, InterruptedException {
  if (debug) {
    listener.getLogger().println("Running mailer");
  }
  // substitute build parameters
  EnvVars env = build.getEnvironment(listener);
  String recip = env.expand(recipients);
  return new MailSender(recip, dontNotifyEveryUnstableBuild, sendToIndividuals,
    descriptor().getCharset()).execute(build, listener);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override public final Environment setUp(AbstractBuild build, final Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
  if (runPreCheckout()) {
    return new Environment() {};
  } else {
    final Context c = new Context();
    setUp(c, build, build.getWorkspace(), launcher, listener, build.getEnvironment(listener));
    return new EnvironmentWrapper(c, launcher);
  }
}

代码示例来源:origin: jenkinsci/debian-package-builder-plugin

public GitCommitHelper(AbstractBuild<?, ?> build, GitSCM scm, Runner runner, String commitMessage, Collection<String> modules) throws IOException, InterruptedException {
  this.commitMessage = commitMessage;
  this.modules = modules;
  this.environment = build.getEnvironment(runner.getListener());
  this.listener = runner.getListener();
  this.gitExe = scm.getGitExe(build.getBuiltOn(), listener);
  this.gitPrefix = scm.getRelativeTargetDir();
  DescriptorImpl descriptor = (DescriptorImpl) Jenkins.getInstance().getDescriptor(DebianPackageBuilder.class);
  this.accountName = descriptor.getAccountName();
  this.accountEmail = descriptor.getAccountEmail();
}

相关文章

微信公众号

最新文章

更多

AbstractBuild类方法