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

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

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

AbstractBuild.getWorkspace介绍

[英]Gets the directory where this build is being built.

Note to implementors: to control where the workspace is created, override AbstractRunner#decideWorkspace(Node,WorkspaceList).
[中]获取生成此生成的目录。
实现者注意:要控制工作空间的创建位置,请重写AbstractRunner#decideWorkspace(节点,工作空间列表)。

代码示例

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

@Override public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
    if (c.disposer != null) {
      c.disposer.tearDown(build, build.getWorkspace(), launcher, listener);
    }
    return true;
  }
}

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

@Deprecated
public SCMRevisionState calcRevisionsFromBuild(AbstractBuild<?,?> build, Launcher launcher, TaskListener listener) throws IOException, InterruptedException {
  return calcRevisionsFromBuild(build, launcher != null ? build.getWorkspace() : null, launcher, listener);
}

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

/**
 * If {@linkplain #getCurrentExecutable() current executable} is {@link AbstractBuild},
 * return the workspace that this executor is using, or null if the build hasn't gotten
 * to that point yet.
 */
public FilePath getCurrentWorkspace() {
  lock.readLock().lock();
  try {
    if (executable == null) {
      return null;
    }
    if (executable instanceof AbstractBuild) {
      AbstractBuild ab = (AbstractBuild) executable;
      return ab.getWorkspace();
    }
    return null;
  } finally {
    lock.readLock().unlock();
  }
}

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

/**
 * Gets the directory where the module is checked out.
 *
 * @return
 *      null if the workspace is on an agent that's not connected.
 * @deprecated as of 1.319
 *      To support concurrent builds of the same project, this method is moved to {@link AbstractBuild}.
 *      For backward compatibility, this method returns the right {@link AbstractBuild#getWorkspace()} if called
 *      from {@link Executor}, and otherwise the workspace of the last build.
 *
 *      <p>
 *      If you are calling this method during a build from an executor, switch it to {@link AbstractBuild#getWorkspace()}.
 *      If you are calling this method to serve a file from the workspace, doing a form validation, etc., then
 *      use {@link #getSomeWorkspace()}
 */
@Deprecated
public final FilePath getWorkspace() {
  AbstractBuild b = getBuildForDeprecatedMethods();
  return b != null ? b.getWorkspace() : null;
}

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

/**
 * Gets some build that has a live workspace.
 *
 * @return null if no such build exists.
 */
public final R getSomeBuildWithWorkspace() {
  int cnt=0;
  for (R b = getLastBuild(); cnt<5 && b!=null; b=b.getPreviousBuild()) {
    FilePath ws = b.getWorkspace();
    if (ws!=null)   return b;
  }
  return null;
}

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

/**
 * Returns the root directories of all checked-out modules.
 * <p>
 * Some SCMs support checking out multiple modules into the same workspace.
 * In these cases, the returned array will have a length greater than one.
 * @return The roots of all modules checked out from the SCM.
 */
public FilePath[] getModuleRoots() {
  FilePath ws = getWorkspace();
  if (ws==null)    return null;
  return getParent().getScm().getModuleRoots(ws, this);
}

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

/**
 * Returns the root directory of the checked-out module.
 * <p>
 * This is usually where {@code pom.xml}, {@code build.xml}
 * and so on exists.
 */
public final FilePath getModuleRoot() {
  FilePath ws = getWorkspace();
  if (ws==null)    return null;
  return getParent().getScm().getModuleRoot(ws, this);
}

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

private R getSomeBuildWithExistingWorkspace() throws IOException, InterruptedException {
  int cnt=0;
  for (R b = getLastBuild(); cnt<5 && b!=null; b=b.getPreviousBuild()) {
    FilePath ws = b.getWorkspace();
    if (ws!=null && ws.exists())   return b;
  }
  return null;
}

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

/**
 * Gets a workspace for some build of this project.
 *
 * <p>
 * This is useful for obtaining a workspace for the purpose of form field validation, where exactly
 * which build the workspace belonged is less important. The implementation makes a cursory effort
 * to find some workspace.
 *
 * @return
 *      null if there's no available workspace.
 * @since 1.319
 */
public final @CheckForNull FilePath getSomeWorkspace() {
  R b = getSomeBuildWithWorkspace();
  if (b!=null) return b.getWorkspace();
  for (WorkspaceBrowser browser : ExtensionList.lookup(WorkspaceBrowser.class)) {
    FilePath f = browser.getWorkspace(this);
    if (f != null) return f;
  }
  return null;
}

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

/**
 * {@inheritDoc}
 * @return Delegates to {@link SimpleBuildStep#perform(Run, FilePath, Launcher, TaskListener)} if possible, always returning true or throwing an error.
 */
@Override
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
  if (this instanceof SimpleBuildStep) {
    // delegate to the overloaded version defined in SimpleBuildStep
    FilePath workspace = build.getWorkspace();
    if (workspace == null) {
      throw new AbortException("no workspace for " + build);
    }
    ((SimpleBuildStep) this).perform(build, workspace, launcher, listener);
    return true;
  } else if (build instanceof Build) {
    // delegate to the legacy signature deprecated in 1.312
    return perform((Build)build,launcher,listener);
  } else {
    return true;
  }
}

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

@Override
  public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
    if (!StringUtils.isEmpty(location) && !StringUtils.isEmpty(file.getName())) {
      listener.getLogger().println("Copying file to "+location);
      FilePath ws = build.getWorkspace();
      if (ws == null) {
        throw new IllegalStateException("The workspace should be created when setUp method is called");
      }
      if (!ALLOW_FOLDER_TRAVERSAL_OUTSIDE_WORKSPACE && !ws.isDescendant(location)) {
        listener.error("Rejecting file path escaping base directory with relative path: " + location);
        // force the build to fail
        return null;
      }
      FilePath locationFilePath = ws.child(location);
      locationFilePath.getParent().mkdirs();
      locationFilePath.copyFrom(file);
      locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build)));
    }
    return new Environment() {};
  }
};

代码示例来源: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: 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

public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException, InterruptedException {
  SCM scm = getScm();
  if(scm==null)
    return true;    // no SCM
  FilePath workspace = build.getWorkspace();
  if(workspace!=null){
    workspace.mkdirs();
  } else {
    throw new AbortException("Cannot checkout SCM, workspace is not defined");
  }
  boolean r = scm.checkout(build, launcher, workspace, listener, changelogFile);
  if (r) {
    // Only calcRevisionsFromBuild if checkout was successful. Note that modern SCM implementations
    // won't reach this line anyway, as they throw AbortExceptions on checkout failure.
    calcPollingBaseline(build, launcher, listener);
  }
  return r;
}

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

private WorkspaceOfflineReason workspaceOffline(R build) throws IOException, InterruptedException {
  FilePath ws = build.getWorkspace();
  Label label = getAssignedLabel();
  if (isAllSuitableNodesOffline(build)) {
    Collection<Cloud> applicableClouds = label == null ? Jenkins.getInstance().clouds : label.getClouds();
    return applicableClouds.isEmpty() ? WorkspaceOfflineReason.all_suitable_nodes_are_offline : WorkspaceOfflineReason.use_ondemand_slave;
  }
  if (ws==null || !ws.exists()) {
    return WorkspaceOfflineReason.nonexisting_workspace;
  }
  Node builtOn = build.getBuiltOn();
  if (builtOn == null) { // node built-on doesn't exist anymore
    return WorkspaceOfflineReason.builton_node_gone;
  }
  if (builtOn.toComputer() == null) { // node still exists, but has 0 executors - o.s.l.t.
    return WorkspaceOfflineReason.builton_node_no_executors;
  }
  return null;
}

代码示例来源: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

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

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

/**
 * Wipes out the workspace.
 */
@RequirePOST
public HttpResponse doDoWipeOutWorkspace() throws IOException, ServletException, InterruptedException {
  checkPermission(Functions.isWipeOutPermissionEnabled() ? WIPEOUT : BUILD);
  R b = getSomeBuildWithWorkspace();
  FilePath ws = b!=null ? b.getWorkspace() : null;
  if (ws!=null && getScm().processWorkspaceBeforeDeletion(this, ws, b.getBuiltOn())) {
    ws.deleteRecursive();
    for (WorkspaceListener wl : WorkspaceListener.all()) {
      wl.afterDelete(this);
    }
    return new HttpRedirect(".");
  } else {
    // If we get here, that means the SCM blocked the workspace deletion.
    return new ForwardToView(this,"wipeOutWorkspaceBlocked.jelly");
  }
}

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

public boolean perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
  FilePath ws = build.getWorkspace();
  if (ws == null) {
    Node node = build.getBuiltOn();

相关文章

微信公众号

最新文章

更多

AbstractBuild类方法