本文整理了Java中jenkins.model.Jenkins.getWorkspaceFor()
方法的一些代码示例,展示了Jenkins.getWorkspaceFor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getWorkspaceFor()
方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getWorkspaceFor
暂无
代码示例来源:origin: org.jenkins-ci.plugins/disk-usage
private boolean isContainedInWorkspace(TopLevelItem item, Node node, String path){
if(node instanceof Slave){
Slave slave = (Slave) node;
return path.contains(slave.getRemoteFS());
}
else{
if(node instanceof Jenkins){
FilePath file = Jenkins.getInstance().getWorkspaceFor(item);
return path.contains(file.getRemote());
}
else{
try{
return path.contains(node.getWorkspaceFor(item).getRemote());
}
catch(Exception e){
return false;
}
}
}
}
代码示例来源:origin: org.jenkins-ci.plugins/copy-to-slave
projectWorkspaceOnMaster = Jenkins.getInstance().getWorkspaceFor(freeStyleProject);
String pathOnMaster = Jenkins.getInstance().getWorkspaceFor((TopLevelItem)project.getRootProject()).getRemote();
String parts[] = build.getWorkspace().getRemote().
split("workspace" + File.separator + project.getRootProject().getName());
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Test public void loaderReleased() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
r.jenkins.getWorkspaceFor(p).child("lib.groovy").write(CpsFlowExecutionMemoryTest.class.getName() + ".register(this)", null);
p.setDefinition(new CpsFlowDefinition(CpsFlowExecutionMemoryTest.class.getName() + ".register(this); node {load 'lib.groovy'; evaluate(readFile('lib.groovy'))}", false));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
assertFalse(((CpsFlowExecution) b.getExecution()).getProgramDataFile().exists());
assertFalse(LOADERS.isEmpty());
{ // TODO it seems that the call to CpsFlowExecutionMemoryTest.register(Object) on a Script1 parameter creates a MetaMethodIndex.Entry.cachedStaticMethod.
// In other words any call to a foundational API might leak classes. Why does Groovy need to do this?
// Unclear whether this is a problem in a realistic environment; for the moment, suppressing it so the test can run with no SoftReference.
MetaClass metaClass = ClassInfo.getClassInfo(CpsFlowExecutionMemoryTest.class).getMetaClass();
Method clearInvocationCaches = metaClass.getClass().getDeclaredMethod("clearInvocationCaches");
clearInvocationCaches.setAccessible(true);
clearInvocationCaches.invoke(metaClass);
}
for (WeakReference<ClassLoader> loaderRef : LOADERS) {
MemoryAssert.assertGC(loaderRef, false);
}
}
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
story.j.jenkins.getWorkspaceFor(p).child("f1.groovy").write("echo 'original first part'", null);
story.j.jenkins.getWorkspaceFor(p).child("f2.groovy").write("echo 'original second part'", null);
p.setDefinition(new CpsFlowDefinition("node {load 'f1.groovy'}; semaphore 'wait'; node {load 'f2.groovy'}", true));
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p");
jenkins.getWorkspaceFor(p).child("a.groovy").write("def call(arg) {echo \"a ran on ${arg}\"}; this", null);
ScriptApproval.get().approveSignature("method groovy.lang.Binding getVariables");
jenkins.getWorkspaceFor(p).child("b.groovy").write("def m(arg) {echo \"${this} binding=${binding.variables}\"; a(\"${arg} from b\")}; this", null);
// Control case:
// TODO if you enable sandbox here, build fails: NoSuchMethodError: No such DSL method 'a' found among […]
// 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).
// Works fine if you use a.call(…) rather than a(…).
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));
story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
// Test case:
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));
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
SemaphoreStep.waitForStart("wait/1", b);
}
});
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(join(
"def touch(f) { writeFile text: '', file: f }",
"node {",
" parallel(aa: {touch('a')}, bb: {touch('b')})",
"}"
), false));
startBuilding().get();
assertBuildCompletedSuccessfully();
assertTrue(jenkins().getWorkspaceFor(p).child("a").exists());
assertTrue(jenkins().getWorkspaceFor(p).child("b").exists());
}
});
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Test public void load() throws Exception {
j.jenkins.getWorkspaceFor(p).child("lib.groovy").write("def m() {semaphore 'here'}; this", null);
p.setDefinition(new CpsFlowDefinition("def lib; node {lib = load 'lib.groovy'}; lib.m()", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("here/1", b);
CpsThreadDump td = b.getAction(CpsThreadDumpAction.class).threadDumpSynchronous();
td.print(System.out);
assertStackTrace(td.getThreads().get(0),
"DSL.semaphore(waiting on here/1)",
"Script1.m(Script1.groovy:1)",
"WorkflowScript.run(WorkflowScript:1)");
}
代码示例来源:origin: jenkinsci/junit-plugin
@Issue("JENKINS-48178")
@Test
public void currentBuildResultUnstable() throws Exception {
WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "currentBuildResultUnstable");
j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
" node {\n" +
" def results = junit(testResults: '*.xml')\n" + // node id 7
" assert results.totalCount == 8\n" +
" assert currentBuild.result == 'UNSTABLE'\n" +
" }\n" +
"}\n", true));
FilePath ws = rule.jenkins.getWorkspaceFor(j);
FilePath testFile = ws.child("test-result.xml");
testFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-first-2.xml"));
rule.assertBuildStatus(Result.UNSTABLE, rule.waitForCompletion(j.scheduleBuild2(0).waitForStart()));
}
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p");
jenkins.getWorkspaceFor(p).child("test.groovy").write(
"def answer(i) { return i*2; }\n" +
"def i=21;\n" +
"semaphore 'watchB'\n" +
"return answer(i);\n", null);
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" println 'started'\n" +
" def o = load 'test.groovy'\n" +
" println 'o=' + o;\n" +
"}", false));
// get the build going
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
// wait until the executor gets assigned and the execution pauses
SemaphoreStep.waitForStart("watchB/1", b);
assertTrue(JenkinsRule.getLog(b), b.isBuilding());
}
});
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p");
jenkins.getWorkspaceFor(p).child("test.groovy").write(
"def answer(i) { return i*2; }\n" +
"def foo(body) {\n" +
" def i = body()\n" +
" semaphore 'watchA'\n" +
" return answer(i);\n" +
"}\n" +
"return this;", null);
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" println 'started'\n" +
" def o = load 'test.groovy'\n" +
" println 'o=' + o.foo({21})\n" +
"}", false));
// get the build going
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
// wait until the executor gets assigned and the execution pauses
SemaphoreStep.waitForStart("watchA/1", b);
assertTrue(JenkinsRule.getLog(b), b.isBuilding());
}
});
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(join(
"import "+AbortException.class.getName(),
"node {",
" try {",
" parallel(",
" b: { error 'died' },",
// make sure this branch takes longer than a
" a: { sleep 3; writeFile text: '', file: 'a.done' }",
" )",
" assert false;",
" } catch (AbortException e) {",
" assert e.message == 'died'",
" }",
"}"
), false));
startBuilding().get();
assertBuildCompletedSuccessfully();
assert jenkins().getWorkspaceFor(p).child("a.done").exists();
buildTable();
shouldHaveParallelStepsInTheOrder("b","a");
}
});
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(join(
"import "+AbortException.class.getName(),
"node {",
" try {",
" parallel(",
" b: { error 'died' },",
// make sure this branch takes longer than a
" a: { sleep 25; writeFile text: '', file: 'a.done' },",
" failFast: true",
" )",
" assert false",
" } catch (AbortException e) {",
" assert e.message == 'died'",
" }",
"}"
), false));
startBuilding().get();
assertBuildCompletedSuccessfully();
Assert.assertFalse("a should have aborted", jenkins().getWorkspaceFor(p).child("a.done").exists());
}
});
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
WorkflowJob p = jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(2);
SemaphoreStep.success("wait/1", null);
story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
// Better case:
jenkins.getWorkspaceFor(p).child("b.groovy").write("def m(a, arg) {a(\"${arg} from b\")}; this", null);
p.setDefinition(new CpsFlowDefinition("def a; def b; node {a = load 'a.groovy'; b = load 'b.groovy'}; b.m(a, 'value')", true));
story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
});
代码示例来源:origin: jenkinsci/junit-plugin
@Test
public void singleStep() throws Exception {
WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "singleStep");
j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
" node {\n" +
" def results = junit(testResults: '*.xml')\n" + // node id 7
" assert results.totalCount == 6\n" +
" }\n" +
"}\n", true));
FilePath ws = rule.jenkins.getWorkspaceFor(j);
FilePath testFile = ws.child("test-result.xml");
testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
WorkflowRun r = rule.buildAndAssertSuccess(j);
TestResultAction action = r.getAction(TestResultAction.class);
assertNotNull(action);
assertEquals(1, action.getResult().getSuites().size());
assertEquals(6, action.getTotalCount());
assertExpectedResults(r, 1, 6, "7");
// Case result display names shouldn't include stage, since there's only one stage.
for (CaseResult c : action.getPassedTests()) {
assertEquals(c.getTransformedTestName(), c.getDisplayName());
}
}
代码示例来源:origin: jenkinsci/junit-plugin
@Test
public void parallelInStage() throws Exception {
WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "parallelInStage");
FilePath ws = rule.jenkins.getWorkspaceFor(j);
FilePath testFile = ws.child("first-result.xml");
testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
FilePath secondTestFile = ws.child("second-result.xml");
secondTestFile.copyFrom(TestResultTest.class.getResource("junit-report-2874.xml"));
FilePath thirdTestFile = ws.child("third-result.xml");
thirdTestFile.copyFrom(TestResultTest.class.getResource("junit-report-nested-testsuites.xml"));
j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
" node {\n" +
" parallel(a: { def first = junit(testResults: 'first-result.xml'); assert first.totalCount == 6 },\n" +
" b: { def second = junit(testResults: 'second-result.xml'); assert second.totalCount == 1 },\n" +
" c: { def third = junit(testResults: 'third-result.xml'); assert third.totalCount == 3 })\n" +
" }\n" +
"}\n", true
));
WorkflowRun r = rule.assertBuildStatus(Result.UNSTABLE,
rule.waitForCompletion(j.scheduleBuild2(0).waitForStart()));
TestResultAction action = r.getAction(TestResultAction.class);
assertNotNull(action);
assertEquals(5, action.getResult().getSuites().size());
assertEquals(10, action.getTotalCount());
assertBranchResults(r, 1, 6, "a", "first");
assertBranchResults(r, 1, 1, "b", "first");
assertBranchResults(r, 3, 3, "c", "first");
assertStageResults(r, 5, 10, "first");
}
代码示例来源:origin: jenkinsci/junit-plugin
public void stageInParallel() throws Exception {
WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "stageInParallel");
FilePath ws = rule.jenkins.getWorkspaceFor(j);
FilePath testFile = ws.child("first-result.xml");
testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
FilePath pkgDir = story.j.jenkins.getWorkspaceFor(p).child("src/org/foo/devops");
pkgDir.mkdirs();
pkgDir.child("Utility.groovy").write("package org.foo.devops\n" +
代码示例来源:origin: jenkinsci/junit-plugin
" }\n" +
"}\n", true));
FilePath ws = rule.jenkins.getWorkspaceFor(j);
FilePath testFile = ws.child("first-result.xml");
testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
代码示例来源:origin: jenkinsci/junit-plugin
" }\n" +
"}\n", true));
FilePath ws = rule.jenkins.getWorkspaceFor(j);
FilePath testFile = ws.child("first-result.xml");
testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
代码示例来源:origin: jenkinsci/workflow-cps-plugin
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
// As in loadStep, will set up a main and auxiliary script.
FilePath f = story.j.jenkins.getWorkspaceFor(p).child("f.groovy");
f.write("'original text'", null);
p.setDefinition(new CpsFlowDefinition("node {def t = load 'f.groovy'; echo \"got ${t}\"}", true));
WorkflowRun b1 = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("got original text", b1);
// s/got/received/ on main script
assertEquals(0, new CLICommandInvoker(story.j, "replay-pipeline").withStdin(IOUtils.toInputStream("node {def t = load 'f.groovy'; echo \"received ${t}\"}")).invokeWithArgs("p").returnCode());
story.j.waitUntilNoActivity();
WorkflowRun b2 = p.getLastBuild();
assertEquals(2, b2.getNumber());
story.j.assertLogContains("received original text", b2);
// s/original/new/ on auxiliary script, and explicitly asking to replay #1 rather than the latest
assertEquals(0, new CLICommandInvoker(story.j, "replay-pipeline").withStdin(IOUtils.toInputStream("'new text'")).invokeWithArgs("p", "-n", "1", "-s", "Script1").returnCode());
story.j.waitUntilNoActivity();
WorkflowRun b3 = p.getLastBuild();
assertEquals(3, b3.getNumber());
// Main script picked up from #1, not #2.
story.j.assertLogContains("got new text", b3);
}
});
内容来源于网络,如有侵权,请联系作者删除!