hudson.model.Environment类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(145)

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

Environment介绍

[英]Represents some resources that are set up for the duration of a build to be torn down when the build is over.

This is often used to run a parallel server necessary during a build, such as an application server, a database reserved for the build, X server for performing UI tests, etc.

By having a plugin that does this, instead of asking each build script to do this, we can simplify the build script. Environment abstraction also gives you guaranteed "tear down" phase, so that such resource won't keep running forever.
[中]表示在生成期间设置的一些资源,这些资源将在生成结束时被拆除。
这通常用于运行构建期间所需的并行服务器,例如应用程序服务器、为构建保留的数据库、用于执行UI测试的X服务器等。
通过有一个插件来实现这一点,我们可以简化构建脚本,而不是要求每个构建脚本都这样做。环境抽象还为您提供了有保证的“拆卸”阶段,这样这些资源就不会永远运行。

代码示例

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

  1. @Override
  2. public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
  3. EnvVars env = super.getEnvironment(log);
  4. FilePath ws = getWorkspace();
  5. if (ws!=null) // if this is done very early on in the build, workspace may not be decided yet. see HUDSON-3997
  6. env.put("WORKSPACE", ws.getRemote());
  7. project.getScm().buildEnvVars(this,env);
  8. if (buildEnvironments!=null)
  9. for (Environment e : buildEnvironments)
  10. e.buildEnvVars(env);
  11. for (EnvironmentContributingAction a : getActions(EnvironmentContributingAction.class))
  12. a.buildEnvVars(this,env);
  13. EnvVars.resolve(env);
  14. return env;
  15. }

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

  1. @Override
  2. public Environment setUp(AbstractBuild build, Launcher launcher,
  3. BuildListener listener) throws IOException, InterruptedException {
  4. return Environment.create(envVars);
  5. }

代码示例来源:origin: org.jvnet.hudson.plugins/ivy

  1. return Result.FAILURE;
  2. buildEnvironments.add(e);
  3. e.buildEnvVars(envVars); // #3502: too late for
  4. if (!buildEnvironments.get(i).tearDown(IvyModuleSetBuild.this, listener)) {
  5. failed = true;

代码示例来源:origin: groupon/DotCi

  1. public boolean tearDownBuildEnvironments(final BuildListener listener) throws IOException, InterruptedException {
  2. boolean failed = false;
  3. final List<Environment> buildEnvironments = getBuildEnvironments();
  4. for (int i = buildEnvironments.size() - 1; i >= 0; i--) {
  5. if (!buildEnvironments.get(i).tearDown(this.build, listener)) {
  6. failed = true;
  7. }
  8. }
  9. return failed;
  10. }

代码示例来源:origin: org.hudsonci.plugins/ivy

  1. return Result.FAILURE;
  2. buildEnvironments.add(e);
  3. e.buildEnvVars(envVars); // #3502: too late for
  4. if (!buildEnvironments.get(i).tearDown(IvyModuleSetBuild.this, listener)) {
  5. failed = true;

代码示例来源:origin: com.cloudbees.plugins/build-flow-plugin

  1. protected Result doRun(BuildListener listener) throws Exception {
  2. if(!preBuild(listener, project.getPublishersList()))
  3. return FAILURE;
  4. try {
  5. setResult(SUCCESS);
  6. if (dslFile != null) {
  7. listener.getLogger().printf("[build-flow] reading DSL from file '%s'\n", dslFile);
  8. String fileContent = getWorkspace().child(dslFile).readToString();
  9. new FlowDSL().executeFlowScript(FlowRun.this, fileContent, listener);
  10. } else {
  11. new FlowDSL().executeFlowScript(FlowRun.this, dsl, listener);
  12. }
  13. } finally {
  14. boolean failed=false;
  15. for( int i=buildEnvironments.size()-1; i>=0; i-- ) {
  16. if (!buildEnvironments.get(i).tearDown(FlowRun.this,listener)) {
  17. failed=true;
  18. }
  19. }
  20. if (failed) return Result.FAILURE;
  21. }
  22. return getState().getResult();
  23. }

代码示例来源:origin: jenkinsci/envinject-plugin

  1. @Nonnull
  2. public static Map<String, String> getEnvVarsPreviousSteps(
  3. @Nonnull Run<?, ?> build, @Nonnull EnvInjectLogger logger)
  4. throws IOException, InterruptedException, EnvInjectException {
  5. Map<String, String> result = new HashMap<String, String>();
  6. // Env vars contributed by build wrappers; no replacement in Pipeline
  7. if (build instanceof AbstractBuild) {
  8. List<Environment> environmentList = ((AbstractBuild)build).getEnvironments();
  9. if (environmentList != null) {
  10. for (Environment e : environmentList) {
  11. if (e != null) {
  12. e.buildEnvVars(result);
  13. }
  14. }
  15. }
  16. }
  17. EnvInjectPluginAction envInjectAction = build.getAction(EnvInjectPluginAction.class);
  18. if (envInjectAction != null) {
  19. result.putAll(getCurrentInjectedEnvVars(envInjectAction));
  20. //Add build variables with axis for a MatrixRun
  21. if (build instanceof MatrixRun) {
  22. result.putAll(((MatrixRun)build).getBuildVariables());
  23. }
  24. } else {
  25. result.putAll(EnvInjectVariableGetter.getJenkinsSystemEnvVars(false));
  26. result.putAll(getBuildVariables(build, logger));
  27. }
  28. return result;
  29. }

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

  1. return Result.FAILURE;
  2. buildEnvironments.add(e);
  3. e.buildEnvVars(envVars); // #3502: too late for
  4. if (!buildEnvironments.get(i).tearDown(IvyModuleSetBuild.this, listener)) {
  5. failed = true;

代码示例来源:origin: org.hudsonci.plugins/ivy

  1. if (!buildEnvironments.get(i).tearDown(IvyBuild.this, listener)) {
  2. failed = true;

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

  1. @Override
  2. public Environment setUp(AbstractBuild build, Launcher launcher,
  3. BuildListener listener) throws IOException, InterruptedException {
  4. return Environment.create(envVars);
  5. }

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

  1. private EnvVars buildContainerEnvironment() throws IOException, InterruptedException {
  2. if (this.env == null) {
  3. this.env = runInContainer.getDocker().getEnv(runInContainer.container, launcher);
  4. }
  5. EnvVars environment = new EnvVars(env);
  6. // Let BuildWrapper customize environment, including PATH
  7. for (Environment e : build.getEnvironments()) {
  8. e.buildEnvVars(environment);
  9. }
  10. return environment;
  11. }

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

  1. return (r = Result.FAILURE);
  2. buildEnvironments.add(e);
  3. e.buildEnvVars(envVars); // #3502: too late for getEnvironment to do this
  4. if (!buildEnvironments.get(i).tearDown(MavenModuleSetBuild.this,listener)) {
  5. failed=true;

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

  1. if (!buildEnvironments.get(i).tearDown(IvyBuild.this, listener)) {
  2. failed = true;

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

  1. @Override
  2. public Environment setUp(AbstractBuild build, Launcher launcher,
  3. BuildListener listener) throws IOException, InterruptedException {
  4. return Environment.create(envVars);
  5. }

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

  1. @Override
  2. public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
  3. EnvVars env = super.getEnvironment(log);
  4. FilePath ws = getWorkspace();
  5. if (ws!=null) // if this is done very early on in the build, workspace may not be decided yet. see HUDSON-3997
  6. env.put("WORKSPACE", ws.getRemote());
  7. project.getScm().buildEnvVars(this,env);
  8. if (buildEnvironments!=null)
  9. for (Environment e : buildEnvironments)
  10. e.buildEnvVars(env);
  11. for (EnvironmentContributingAction a : getActions(EnvironmentContributingAction.class))
  12. a.buildEnvVars(this,env);
  13. EnvVars.resolve(env);
  14. return env;
  15. }

代码示例来源:origin: org.jvnet.hudson.plugins/ivy

  1. if (!buildEnvironments.get(i).tearDown(IvyBuild.this, listener)) {
  2. failed = true;

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

  1. @Override
  2. public Environment setUp(AbstractBuild build, Launcher launcher,
  3. BuildListener listener) throws IOException, InterruptedException {
  4. return Environment.create(envVars);
  5. }

代码示例来源:origin: org.hudsonci.plugins/git

  1. Environment environment = nodeProperty.setUp(b, launcher, (BuildListener) buildListener);
  2. if (environment != null) {
  3. environment.buildEnvVars(env);
  4. Environment environment = nodeProperty.setUp(b, launcher, buildListener);
  5. if (environment != null) {
  6. environment.buildEnvVars(env);

代码示例来源:origin: jenkinsci/promoted-builds-plugin

  1. if (!buildEnvironments.get(i).tearDown(Promotion.this,listener)) {
  2. failed=true;

代码示例来源:origin: hudson/hudson-2.x

  1. @Override
  2. public Environment setUp(AbstractBuild build, Launcher launcher,
  3. BuildListener listener) throws IOException, InterruptedException {
  4. return Environment.create(envVars);
  5. }

相关文章