jenkins.model.Jenkins.getWorkspaceFor()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(15.7k)|赞(0)|评价(0)|浏览(207)

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

Jenkins.getWorkspaceFor介绍

暂无

代码示例

代码示例来源: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: org.jenkins-ci.plugins/copy-to-slave

  1. projectWorkspaceOnMaster = Jenkins.getInstance().getWorkspaceFor(freeStyleProject);
  2. String pathOnMaster = Jenkins.getInstance().getWorkspaceFor((TopLevelItem)project.getRootProject()).getRemote();
  3. String parts[] = build.getWorkspace().getRemote().
  4. split("workspace" + File.separator + project.getRootProject().getName());

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

  1. @Test public void loaderReleased() throws Exception {
  2. WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  3. r.jenkins.getWorkspaceFor(p).child("lib.groovy").write(CpsFlowExecutionMemoryTest.class.getName() + ".register(this)", null);
  4. p.setDefinition(new CpsFlowDefinition(CpsFlowExecutionMemoryTest.class.getName() + ".register(this); node {load 'lib.groovy'; evaluate(readFile('lib.groovy'))}", false));
  5. WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  6. assertFalse(((CpsFlowExecution) b.getExecution()).getProgramDataFile().exists());
  7. assertFalse(LOADERS.isEmpty());
  8. { // TODO it seems that the call to CpsFlowExecutionMemoryTest.register(Object) on a Script1 parameter creates a MetaMethodIndex.Entry.cachedStaticMethod.
  9. // In other words any call to a foundational API might leak classes. Why does Groovy need to do this?
  10. // Unclear whether this is a problem in a realistic environment; for the moment, suppressing it so the test can run with no SoftReference.
  11. MetaClass metaClass = ClassInfo.getClassInfo(CpsFlowExecutionMemoryTest.class).getMetaClass();
  12. Method clearInvocationCaches = metaClass.getClass().getDeclaredMethod("clearInvocationCaches");
  13. clearInvocationCaches.setAccessible(true);
  14. clearInvocationCaches.invoke(metaClass);
  15. }
  16. for (WeakReference<ClassLoader> loaderRef : LOADERS) {
  17. MemoryAssert.assertGC(loaderRef, false);
  18. }
  19. }

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

  1. @Override public void evaluate() throws Throwable {
  2. WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
  3. story.j.jenkins.getWorkspaceFor(p).child("f1.groovy").write("echo 'original first part'", null);
  4. story.j.jenkins.getWorkspaceFor(p).child("f2.groovy").write("echo 'original second part'", null);
  5. p.setDefinition(new CpsFlowDefinition("node {load 'f1.groovy'}; semaphore 'wait'; node {load 'f2.groovy'}", true));

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

  1. @Override public void evaluate() throws Throwable {
  2. WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p");
  3. jenkins.getWorkspaceFor(p).child("a.groovy").write("def call(arg) {echo \"a ran on ${arg}\"}; this", null);
  4. ScriptApproval.get().approveSignature("method groovy.lang.Binding getVariables");
  5. jenkins.getWorkspaceFor(p).child("b.groovy").write("def m(arg) {echo \"${this} binding=${binding.variables}\"; a(\"${arg} from b\")}; this", null);
  6. // Control case:
  7. // TODO if you enable sandbox here, build fails: NoSuchMethodError: No such DSL method 'a' found among […]
  8. // SandboxInterceptor.onMethodCall is given Script2 as the receiver and "a" as the method, when really it should be asked about onGetProperty(Script2.a) followed by onMethodCall(Script1.call).
  9. // Works fine if you use a.call(…) rather than a(…).
  10. p.setDefinition(new CpsFlowDefinition("a = 0; node {a = load 'a.groovy'}; def b; node {b = load 'b.groovy'}; echo \"${this} binding=${binding.variables}\"; b.m('value')", false));
  11. story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
  12. // Test case:
  13. p.setDefinition(new CpsFlowDefinition("a = 0; node {a = load 'a.groovy'}; semaphore 'wait'; def b; node {b = load 'b.groovy'}; echo \"${this} binding=${binding.variables}\"; b.m('value')", /* TODO ditto */false));
  14. WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
  15. SemaphoreStep.waitForStart("wait/1", b);
  16. }
  17. });

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

  1. @Override public void evaluate() throws Throwable {
  2. p = jenkins().createProject(WorkflowJob.class, "demo");
  3. p.setDefinition(new CpsFlowDefinition(join(
  4. "def touch(f) { writeFile text: '', file: f }",
  5. "node {",
  6. " parallel(aa: {touch('a')}, bb: {touch('b')})",
  7. "}"
  8. ), false));
  9. startBuilding().get();
  10. assertBuildCompletedSuccessfully();
  11. assertTrue(jenkins().getWorkspaceFor(p).child("a").exists());
  12. assertTrue(jenkins().getWorkspaceFor(p).child("b").exists());
  13. }
  14. });

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

  1. @Test public void load() throws Exception {
  2. j.jenkins.getWorkspaceFor(p).child("lib.groovy").write("def m() {semaphore 'here'}; this", null);
  3. p.setDefinition(new CpsFlowDefinition("def lib; node {lib = load 'lib.groovy'}; lib.m()", true));
  4. WorkflowRun b = p.scheduleBuild2(0).waitForStart();
  5. SemaphoreStep.waitForStart("here/1", b);
  6. CpsThreadDump td = b.getAction(CpsThreadDumpAction.class).threadDumpSynchronous();
  7. td.print(System.out);
  8. assertStackTrace(td.getThreads().get(0),
  9. "DSL.semaphore(waiting on here/1)",
  10. "Script1.m(Script1.groovy:1)",
  11. "WorkflowScript.run(WorkflowScript:1)");
  12. }

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

  1. @Issue("JENKINS-48178")
  2. @Test
  3. public void currentBuildResultUnstable() throws Exception {
  4. WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "currentBuildResultUnstable");
  5. j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
  6. " node {\n" +
  7. " def results = junit(testResults: '*.xml')\n" + // node id 7
  8. " assert results.totalCount == 8\n" +
  9. " assert currentBuild.result == 'UNSTABLE'\n" +
  10. " }\n" +
  11. "}\n", true));
  12. FilePath ws = rule.jenkins.getWorkspaceFor(j);
  13. FilePath testFile = ws.child("test-result.xml");
  14. testFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-first-2.xml"));
  15. rule.assertBuildStatus(Result.UNSTABLE, rule.waitForCompletion(j.scheduleBuild2(0).waitForStart()));
  16. }

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

  1. @Override public void evaluate() throws Throwable {
  2. WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p");
  3. jenkins.getWorkspaceFor(p).child("test.groovy").write(
  4. "def answer(i) { return i*2; }\n" +
  5. "def i=21;\n" +
  6. "semaphore 'watchB'\n" +
  7. "return answer(i);\n", null);
  8. p.setDefinition(new CpsFlowDefinition(
  9. "node {\n" +
  10. " println 'started'\n" +
  11. " def o = load 'test.groovy'\n" +
  12. " println 'o=' + o;\n" +
  13. "}", false));
  14. // get the build going
  15. WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
  16. // wait until the executor gets assigned and the execution pauses
  17. SemaphoreStep.waitForStart("watchB/1", b);
  18. assertTrue(JenkinsRule.getLog(b), b.isBuilding());
  19. }
  20. });

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

  1. @Override public void evaluate() throws Throwable {
  2. WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p");
  3. jenkins.getWorkspaceFor(p).child("test.groovy").write(
  4. "def answer(i) { return i*2; }\n" +
  5. "def foo(body) {\n" +
  6. " def i = body()\n" +
  7. " semaphore 'watchA'\n" +
  8. " return answer(i);\n" +
  9. "}\n" +
  10. "return this;", null);
  11. p.setDefinition(new CpsFlowDefinition(
  12. "node {\n" +
  13. " println 'started'\n" +
  14. " def o = load 'test.groovy'\n" +
  15. " println 'o=' + o.foo({21})\n" +
  16. "}", false));
  17. // get the build going
  18. WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
  19. // wait until the executor gets assigned and the execution pauses
  20. SemaphoreStep.waitForStart("watchA/1", b);
  21. assertTrue(JenkinsRule.getLog(b), b.isBuilding());
  22. }
  23. });

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

  1. @Override public void evaluate() throws Throwable {
  2. p = jenkins().createProject(WorkflowJob.class, "demo");
  3. p.setDefinition(new CpsFlowDefinition(join(
  4. "import "+AbortException.class.getName(),
  5. "node {",
  6. " try {",
  7. " parallel(",
  8. " b: { error 'died' },",
  9. // make sure this branch takes longer than a
  10. " a: { sleep 3; writeFile text: '', file: 'a.done' }",
  11. " )",
  12. " assert false;",
  13. " } catch (AbortException e) {",
  14. " assert e.message == 'died'",
  15. " }",
  16. "}"
  17. ), false));
  18. startBuilding().get();
  19. assertBuildCompletedSuccessfully();
  20. assert jenkins().getWorkspaceFor(p).child("a.done").exists();
  21. buildTable();
  22. shouldHaveParallelStepsInTheOrder("b","a");
  23. }
  24. });

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

  1. @Override public void evaluate() throws Throwable {
  2. p = jenkins().createProject(WorkflowJob.class, "demo");
  3. p.setDefinition(new CpsFlowDefinition(join(
  4. "import "+AbortException.class.getName(),
  5. "node {",
  6. " try {",
  7. " parallel(",
  8. " b: { error 'died' },",
  9. // make sure this branch takes longer than a
  10. " a: { sleep 25; writeFile text: '', file: 'a.done' },",
  11. " failFast: true",
  12. " )",
  13. " assert false",
  14. " } catch (AbortException e) {",
  15. " assert e.message == 'died'",
  16. " }",
  17. "}"
  18. ), false));
  19. startBuilding().get();
  20. assertBuildCompletedSuccessfully();
  21. Assert.assertFalse("a should have aborted", jenkins().getWorkspaceFor(p).child("a.done").exists());
  22. }
  23. });

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

  1. @Override public void evaluate() throws Throwable {
  2. WorkflowJob p = jenkins.getItemByFullName("p", WorkflowJob.class);
  3. WorkflowRun b = p.getBuildByNumber(2);
  4. SemaphoreStep.success("wait/1", null);
  5. story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
  6. // Better case:
  7. jenkins.getWorkspaceFor(p).child("b.groovy").write("def m(a, arg) {a(\"${arg} from b\")}; this", null);
  8. p.setDefinition(new CpsFlowDefinition("def a; def b; node {a = load 'a.groovy'; b = load 'b.groovy'}; b.m(a, 'value')", true));
  9. story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
  10. }
  11. });

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

  1. @Test
  2. public void singleStep() throws Exception {
  3. WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "singleStep");
  4. j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
  5. " node {\n" +
  6. " def results = junit(testResults: '*.xml')\n" + // node id 7
  7. " assert results.totalCount == 6\n" +
  8. " }\n" +
  9. "}\n", true));
  10. FilePath ws = rule.jenkins.getWorkspaceFor(j);
  11. FilePath testFile = ws.child("test-result.xml");
  12. testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
  13. WorkflowRun r = rule.buildAndAssertSuccess(j);
  14. TestResultAction action = r.getAction(TestResultAction.class);
  15. assertNotNull(action);
  16. assertEquals(1, action.getResult().getSuites().size());
  17. assertEquals(6, action.getTotalCount());
  18. assertExpectedResults(r, 1, 6, "7");
  19. // Case result display names shouldn't include stage, since there's only one stage.
  20. for (CaseResult c : action.getPassedTests()) {
  21. assertEquals(c.getTransformedTestName(), c.getDisplayName());
  22. }
  23. }

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

  1. @Test
  2. public void parallelInStage() throws Exception {
  3. WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "parallelInStage");
  4. FilePath ws = rule.jenkins.getWorkspaceFor(j);
  5. FilePath testFile = ws.child("first-result.xml");
  6. testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
  7. FilePath secondTestFile = ws.child("second-result.xml");
  8. secondTestFile.copyFrom(TestResultTest.class.getResource("junit-report-2874.xml"));
  9. FilePath thirdTestFile = ws.child("third-result.xml");
  10. thirdTestFile.copyFrom(TestResultTest.class.getResource("junit-report-nested-testsuites.xml"));
  11. j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
  12. " node {\n" +
  13. " parallel(a: { def first = junit(testResults: 'first-result.xml'); assert first.totalCount == 6 },\n" +
  14. " b: { def second = junit(testResults: 'second-result.xml'); assert second.totalCount == 1 },\n" +
  15. " c: { def third = junit(testResults: 'third-result.xml'); assert third.totalCount == 3 })\n" +
  16. " }\n" +
  17. "}\n", true
  18. ));
  19. WorkflowRun r = rule.assertBuildStatus(Result.UNSTABLE,
  20. rule.waitForCompletion(j.scheduleBuild2(0).waitForStart()));
  21. TestResultAction action = r.getAction(TestResultAction.class);
  22. assertNotNull(action);
  23. assertEquals(5, action.getResult().getSuites().size());
  24. assertEquals(10, action.getTotalCount());
  25. assertBranchResults(r, 1, 6, "a", "first");
  26. assertBranchResults(r, 1, 1, "b", "first");
  27. assertBranchResults(r, 3, 3, "c", "first");
  28. assertStageResults(r, 5, 10, "first");
  29. }

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

  1. public void stageInParallel() throws Exception {
  2. WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "stageInParallel");
  3. FilePath ws = rule.jenkins.getWorkspaceFor(j);
  4. FilePath testFile = ws.child("first-result.xml");
  5. testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));

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

  1. @Override public void evaluate() throws Throwable {
  2. WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
  3. FilePath pkgDir = story.j.jenkins.getWorkspaceFor(p).child("src/org/foo/devops");
  4. pkgDir.mkdirs();
  5. pkgDir.child("Utility.groovy").write("package org.foo.devops\n" +

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

  1. " }\n" +
  2. "}\n", true));
  3. FilePath ws = rule.jenkins.getWorkspaceFor(j);
  4. FilePath testFile = ws.child("first-result.xml");
  5. testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));

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

  1. " }\n" +
  2. "}\n", true));
  3. FilePath ws = rule.jenkins.getWorkspaceFor(j);
  4. FilePath testFile = ws.child("first-result.xml");
  5. testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));

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

  1. @Override public void evaluate() throws Throwable {
  2. WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
  3. // As in loadStep, will set up a main and auxiliary script.
  4. FilePath f = story.j.jenkins.getWorkspaceFor(p).child("f.groovy");
  5. f.write("'original text'", null);
  6. p.setDefinition(new CpsFlowDefinition("node {def t = load 'f.groovy'; echo \"got ${t}\"}", true));
  7. WorkflowRun b1 = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  8. story.j.assertLogContains("got original text", b1);
  9. // s/got/received/ on main script
  10. assertEquals(0, new CLICommandInvoker(story.j, "replay-pipeline").withStdin(IOUtils.toInputStream("node {def t = load 'f.groovy'; echo \"received ${t}\"}")).invokeWithArgs("p").returnCode());
  11. story.j.waitUntilNoActivity();
  12. WorkflowRun b2 = p.getLastBuild();
  13. assertEquals(2, b2.getNumber());
  14. story.j.assertLogContains("received original text", b2);
  15. // s/original/new/ on auxiliary script, and explicitly asking to replay #1 rather than the latest
  16. assertEquals(0, new CLICommandInvoker(story.j, "replay-pipeline").withStdin(IOUtils.toInputStream("'new text'")).invokeWithArgs("p", "-n", "1", "-s", "Script1").returnCode());
  17. story.j.waitUntilNoActivity();
  18. WorkflowRun b3 = p.getLastBuild();
  19. assertEquals(3, b3.getNumber());
  20. // Main script picked up from #1, not #2.
  21. story.j.assertLogContains("got new text", b3);
  22. }
  23. });

相关文章

Jenkins类方法