hudson.model.Node.getWorkspaceFor()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(113)

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

Node.getWorkspaceFor介绍

[英]Returns a "workspace" directory for the given TopLevelItem.

Workspace directory is usually used for keeping out the checked out source code, but it can be used for anything.
[中]返回给定TopLevelItem的“工作区”目录。
工作区目录通常用于隐藏签出的源代码,但它可以用于任何用途。

代码示例

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

  1. FilePath ws = node.getWorkspaceFor(item);
  2. if (ws == null) {
  3. continue; // offline, fine

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

  1. private boolean isContainedInWorkspace(TopLevelItem item, Node node, String path){
  2. if(node instanceof Slave){
  3. Slave slave = (Slave) node;
  4. return path.contains(slave.getRemoteFS());
  5. }
  6. else{
  7. if(node instanceof Jenkins){
  8. FilePath file = Jenkins.getInstance().getWorkspaceFor(item);
  9. return path.contains(file.getRemote());
  10. }
  11. else{
  12. try{
  13. return path.contains(node.getWorkspaceFor(item).getRemote());
  14. }
  15. catch(Exception e){
  16. return false;
  17. }
  18. }
  19. }
  20. }

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

  1. public static FilePath getWorkspacePathFor(
  2. Node n, InheritanceProject project, Map<String, String> values) {
  3. String path = project.getParameterizedWorkspace();
  4. if (path == null || path.isEmpty()) {
  5. return null;
  6. }
  7. //Resolve the path's variables
  8. String resolv = Resolver.resolveSingle(values, path);
  9. if (resolv == null) { return null; }
  10. resolv = resolv.trim();
  11. if (resolv.isEmpty()) { return null; }
  12. //Check if the path looks absolute; if not put it under the node
  13. if (PathMapping.isAbsolute(resolv) == false) {
  14. FilePath root = n.getWorkspaceFor(project);
  15. if (root != null) {
  16. root = root.getParent();
  17. resolv = PathMapping.join(root.getRemote(), resolv);
  18. }
  19. }
  20. return new FilePath(n.getChannel(), resolv);
  21. }

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

  1. protected Lease getParentWorkspaceLease(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
  2. MatrixProject mp = getParent().getParent();
  3. String customWorkspace = mp.getCustomWorkspace();
  4. if (customWorkspace != null) {
  5. final FilePath nodeRoot = n.getRootPath();
  6. if (nodeRoot == null) {
  7. throw new IOException("Cannot retrieve the node's root. Most probably it's offline");
  8. }
  9. // we allow custom workspaces to be concurrently used between jobs.
  10. return Lease.createDummyLease(nodeRoot.child(getEnvironment(listener).expand(customWorkspace)));
  11. }
  12. final FilePath workspace = n.getWorkspaceFor(mp);
  13. if (workspace == null) {
  14. throw new IOException("Cannot retrieve the node's workspace for " + mp + ". Most probably the node is offline");
  15. }
  16. return wsl.allocate(workspace, getParentBuild());
  17. }

代码示例来源:origin: i-m-c/jenkins-inheritance-plugin

  1. FilePath root = n.getWorkspaceFor(project);
  2. if (root != null) {
  3. root = root.getParent();
  4. return n.getWorkspaceFor(project);

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

  1. @Override
  2. protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
  3. if (getTarget() == null) {
  4. throw new IOException("No Promotion target, cannot retrieve workspace");
  5. }
  6. String customWorkspace = Promotion.this.getProject().getCustomWorkspace();
  7. if (customWorkspace != null) {
  8. final FilePath rootPath = n.getRootPath();
  9. if (rootPath == null) {
  10. throw new IOException("Cannot retrieve the root path of the node " + n);
  11. }
  12. // we allow custom workspaces to be concurrently used between jobs.
  13. return Lease.createDummyLease(
  14. rootPath.child(getEnvironment(listener).expand(customWorkspace)));
  15. }
  16. TopLevelItem item = (TopLevelItem)getTarget().getProject();
  17. FilePath workspace = n.getWorkspaceFor(item);
  18. if (workspace == null) {
  19. throw new IOException("Cannot retrieve workspace for " + item + " on the node " + n);
  20. }
  21. return wsl.allocate(workspace, promotionRun);
  22. }

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

  1. FilePath path =null;
  2. try{
  3. path = node.getWorkspaceFor((TopLevelItem)owner);
  4. if(path!=null && path.exists() && (diskUsage.slaveWorkspacesUsage.get(node.getNodeName())==null || !diskUsage.slaveWorkspacesUsage.get(node.getNodeName()).containsKey(path.getRemote()))){
  5. putSlaveWorkspace(node, path.getRemote());

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

  1. public Object readResolve() {
  2. //for keeping backward compatibility
  3. if(diskUsage!=null){
  4. buildDiskUsage = diskUsage.buildUsage;
  5. Node node = build.getBuiltOn();
  6. if(node!=null && diskUsage.wsUsage!=null && diskUsage.wsUsage > 0){
  7. DiskUsageProperty property = (DiskUsageProperty) build.getProject().getProperty(DiskUsageProperty.class);
  8. AbstractProject project = build.getProject().getRootProject();
  9. if(property!=null && (project instanceof TopLevelItem))
  10. property.putSlaveWorkspaceSize(node, node.getWorkspaceFor((TopLevelItem)project).getRemote(), diskUsage.wsUsage);
  11. }
  12. diskUsage=null;
  13. }
  14. return this;
  15. }

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

  1. FilePath ws = node.getWorkspaceFor(item);
  2. if (ws == null) {
  3. continue; // offline, fine

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

  1. throw new Exception(j + " must be a top-level job");
  2. FilePath p = node.getWorkspaceFor((TopLevelItem) j);
  3. if (p == null) {
  4. throw new IllegalStateException(node + " is offline");

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

  1. protected Lease getParentWorkspaceLease(final Node n, final WorkspaceList wsl) throws InterruptedException, IOException {
  2. final DynamicProject mp = getParent().getParent();
  3. final String customWorkspace = mp.getCustomWorkspace();
  4. if (customWorkspace != null) {
  5. // we allow custom workspaces to be concurrently used between
  6. // jobs.
  7. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(this.listener).expand(customWorkspace)));
  8. }
  9. return wsl.allocate(n.getWorkspaceFor(mp), getParentBuild());
  10. }

代码示例来源:origin: io.jenkins.plugins/docker-slaves

  1. throw new Exception(j + " must be a top-level job");
  2. FilePath p = node.getWorkspaceFor((TopLevelItem) j);
  3. if (p == null) {
  4. throw new IllegalStateException(node + " is offline");

代码示例来源:origin: org.jenkins-ci.plugins.workflow/workflow-durable-task-step

  1. throw new Exception(j + " must be a top-level job");
  2. FilePath p = node.getWorkspaceFor((TopLevelItem) j);
  3. if (p == null) {
  4. throw new IllegalStateException(node + " is offline");

代码示例来源:origin: org.jenkins-ci.plugins.workflow/workflow-cps-global-lib

  1. static void doRetrieve(String name, boolean changelog, @Nonnull SCM scm, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception {
  2. // Adapted from CpsScmFlowDefinition:
  3. SCMStep delegate = new GenericSCMStep(scm);
  4. delegate.setPoll(false); // TODO we have no API for determining if a given SCMHead is branch-like or tag-like; would we want to turn on polling if the former?
  5. delegate.setChangelog(changelog);
  6. FilePath dir;
  7. Node node = Jenkins.getActiveInstance();
  8. if (run.getParent() instanceof TopLevelItem) {
  9. FilePath baseWorkspace = node.getWorkspaceFor((TopLevelItem) run.getParent());
  10. if (baseWorkspace == null) {
  11. throw new IOException(node.getDisplayName() + " may be offline");
  12. }
  13. dir = baseWorkspace.withSuffix(getFilePathSuffix() + "libs").child(name);
  14. } else { // should not happen, but just in case:
  15. throw new AbortException("Cannot check out in non-top-level build");
  16. }
  17. Computer computer = node.toComputer();
  18. if (computer == null) {
  19. throw new IOException(node.getDisplayName() + " may be offline");
  20. }
  21. try (WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(dir)) {
  22. delegate.checkout(run, lease.path, listener, node.createLauncher(listener));
  23. // Cannot add WorkspaceActionImpl to private CpsFlowExecution.flowStartNodeActions; do we care?
  24. // Copy sources with relevant files from the checkout:
  25. lease.path.copyRecursiveTo("src/**/*.groovy,vars/*.groovy,vars/*.txt,resources/", null, target);
  26. }
  27. }

代码示例来源:origin: org.jenkins-ci.plugins.workflow/workflow-durable-task-step

  1. FilePath baseWorkspace = node.getWorkspaceFor((TopLevelItem) job);
  2. if (baseWorkspace == null) {
  3. throw new IllegalStateException(node + " is offline");

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

  1. Node node = Jenkins.get();
  2. if (build.getParent() instanceof TopLevelItem) {
  3. FilePath baseWorkspace = node.getWorkspaceFor((TopLevelItem) build.getParent());
  4. if (baseWorkspace == null) {
  5. throw new IOException(node.getDisplayName() + " may be offline");

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

  1. @Override
  2. protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
  3. // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'.
  4. String subtree;
  5. if(useShortWorkspaceName) {
  6. subtree = getParent().getDigestName();
  7. } else {
  8. subtree = getParent().getCombination().toString('/','/', true);
  9. }
  10. String customWorkspace = getParent().getParent().getCustomWorkspace();
  11. if (customWorkspace != null) {
  12. // Use custom workspace as defined in the matrix project settings.
  13. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace));
  14. // We allow custom workspaces to be used concurrently between jobs.
  15. return Lease.createDummyLease(ws.child(subtree));
  16. } else {
  17. // Use default workspace as assigned by Hudson.
  18. Node node = getBuiltOn();
  19. FilePath ws = node.getWorkspaceFor(getParent().getParent());
  20. // Allocate unique workspace (not to be shared between jobs and runs).
  21. return wsl.allocate(ws.child(subtree));
  22. }
  23. }
  24. }

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

  1. @Override
  2. protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
  3. // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'.
  4. String subtree;
  5. if (useShortWorkspaceName) {
  6. subtree = getParent().getDigestName();
  7. } else {
  8. subtree = getParent().getCombination().toString('/', '/', true);
  9. }
  10. String customWorkspace = getParent().getParent().getCustomWorkspace();
  11. if (customWorkspace != null) {
  12. // Use custom workspace as defined in the matrix project settings.
  13. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace));
  14. // We allow custom workspaces to be used concurrently between jobs.
  15. return Lease.createDummyLease(ws.child(subtree));
  16. } else {
  17. // Use default workspace as assigned by Hudson.
  18. Node node = getBuiltOn();
  19. FilePath ws = node.getWorkspaceFor(getParent().getParent());
  20. // Allocate unique workspace (not to be shared between jobs and runs).
  21. return wsl.allocate(ws.child(subtree));
  22. }
  23. }
  24. }

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

  1. @Override
  2. protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
  3. // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'.
  4. String subtree;
  5. if(useShortWorkspaceName) {
  6. subtree = getParent().getDigestName();
  7. } else {
  8. subtree = getParent().getCombination().toString('/','/', true);
  9. }
  10. String customWorkspace = getParent().getParent().getCustomWorkspace();
  11. if (customWorkspace != null) {
  12. // Use custom workspace as defined in the matrix project settings.
  13. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace));
  14. // We allow custom workspaces to be used concurrently between jobs.
  15. return Lease.createDummyLease(ws.child(subtree));
  16. } else {
  17. // Use default workspace as assigned by Hudson.
  18. Node node = getBuiltOn();
  19. FilePath ws = node.getWorkspaceFor(getParent().getParent());
  20. // Allocate unique workspace (not to be shared between jobs and runs).
  21. return wsl.allocate(ws.child(subtree));
  22. }
  23. }
  24. }

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

  1. @Override
  2. protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException {
  3. // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'.
  4. String subtree;
  5. if(useShortWorkspaceName) {
  6. subtree = getParent().getDigestName();
  7. } else {
  8. subtree = getParent().getCombination().toString('/','/', true);
  9. }
  10. String customWorkspace = getParent().getParent().getCustomWorkspace();
  11. if (customWorkspace != null) {
  12. // Use custom workspace as defined in the matrix project settings.
  13. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace));
  14. // We allow custom workspaces to be used concurrently between jobs.
  15. return Lease.createDummyLease(ws.child(subtree));
  16. } else {
  17. // Use default workspace as assigned by Hudson.
  18. Node node = getBuiltOn();
  19. FilePath ws = node.getWorkspaceFor(getParent().getParent());
  20. // Allocate unique workspace (not to be shared between jobs and runs).
  21. return wsl.allocate(ws.child(subtree));
  22. }
  23. }
  24. }

相关文章