本文整理汇总了Java中org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep类的典型用法代码示例。如果您正苦于以下问题:Java SemaphoreStep类的具体用法?Java SemaphoreStep怎么用?Java SemaphoreStep使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SemaphoreStep类属于org.jenkinsci.plugins.workflow.test.steps包,在下文中一共展示了SemaphoreStep类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDefaultJenkinsFile
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test
public void testDefaultJenkinsFile() throws Exception {
GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
ConfigFileStore store = globalConfigFiles.get();
Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
"semaphore 'wait'; node {checkout scm; echo readFile('file')}");
store.save(config);
sampleGitRepo.init();
sampleGitRepo.write("file", "initial content");
sampleGitRepo.git("commit", "--all", "--message=flow");
WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
new DefaultBranchPropertyStrategy(new BranchProperty[0])));
WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
SemaphoreStep.waitForStart("wait/1", null);
WorkflowRun b1 = p.getLastBuild();
assertNotNull(b1);
assertEquals(1, b1.getNumber());
SemaphoreStep.success("wait/1", null);
r.assertLogContains("initial content", r.waitForCompletion(b1));
}
示例2: simple
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void simple() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("waitUntil {semaphore 'wait'}; semaphore 'waited'", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b);
SemaphoreStep.success("wait/1", false);
SemaphoreStep.waitForStart("wait/2", b);
SemaphoreStep.success("wait/2", false);
SemaphoreStep.waitForStart("wait/3", b);
SemaphoreStep.success("wait/3", true);
SemaphoreStep.waitForStart("waited/1", b);
SemaphoreStep.success("waited/1", null);
story.j.assertLogContains("Will try again after " + Util.getTimeSpanString(WaitForConditionStep.Execution.MIN_RECURRENCE_PERIOD), story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
}
});
}
示例3: failure
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void failure() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("waitUntil {semaphore 'wait'}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b);
SemaphoreStep.success("wait/1", false);
SemaphoreStep.waitForStart("wait/2", b);
String message = "broken condition";
SemaphoreStep.failure("wait/2", new AbortException(message));
// TODO the following fails (missing message) when run as part of whole suite, but not standalone: story.j.assertLogContains(message, story.j.assertBuildStatus(Result.FAILURE, story.j.waitForCompletion(b)));
story.j.waitForCompletion(b);
story.j.assertBuildStatus(Result.FAILURE, b);
story.j.assertLogContains(message, b); // TODO observed to flake on windows-8-2.32.3: see two `semaphore`s and a “Will try again after 0.25 sec” but no such message
}
});
}
示例4: abortShouldNotRetry
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Issue("JENKINS-41276")
@Test
public void abortShouldNotRetry() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"int count = 0; retry(3) { echo 'trying '+(count++); semaphore 'start'; echo 'NotHere' } echo 'NotHere'", true));
final WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("start/1", b);
ACL.impersonate(User.get("dev").impersonate(), new Runnable() {
@Override public void run() {
b.getExecutor().doStop();
}
});
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
r.assertLogContains("trying 0", b);
r.assertLogContains("Aborted by dev", b);
r.assertLogNotContains("trying 1", b);
r.assertLogNotContains("trying 2", b);
r.assertLogNotContains("NotHere", b);
}
示例5: specialStatus
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void specialStatus() throws Exception {
User.get("smrt");
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"catchError {\n" +
" semaphore 'specialStatus'\n" +
"}", true));
SemaphoreStep.failure("specialStatus/1", new FlowInterruptedException(Result.UNSTABLE, new CauseOfInterruption.UserInterruption("smrt")));
WorkflowRun b = p.scheduleBuild2(0).get();
r.assertLogContains("smrt", r.assertBuildStatus(Result.UNSTABLE, b));
/* TODO fixing this is trickier since CpsFlowExecution.setResult does not implement a public method, and anyway CatchErrorStep in its current location could not refer to FlowExecution:
List<FlowNode> heads = b.getExecution().getCurrentHeads();
assertEquals(1, heads.size());
assertEquals(Result.UNSTABLE, ((FlowEndNode) heads.get(0)).getResult());
*/
}
示例6: parallel
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void parallel() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"parallel a: {\n" +
" node {withEnv(['TOOL=aloc']) {semaphore 'a'; isUnix() ? sh('echo TOOL=$TOOL') : bat('echo TOOL=%TOOL%')}}\n" +
"}, b: {\n" +
" node {withEnv(['TOOL=bloc']) {semaphore 'b'; isUnix() ? sh('echo TOOL=$TOOL') : bat('echo TOOL=%TOOL%')}}\n" +
"}", true));
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
SemaphoreStep.waitForStart("a/1", b);
SemaphoreStep.waitForStart("b/1", b);
SemaphoreStep.success("a/1", null);
SemaphoreStep.success("b/1", null);
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
story.j.assertLogContains("[a] TOOL=aloc", b);
story.j.assertLogContains("[b] TOOL=bloc", b);
}
});
}
示例7: smokes
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Issue("JENKINS-26942")
@Test public void smokes() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" writeFile file: 'subdir/fname', text: 'whatever'\n" +
" writeFile file: 'subdir/other', text: 'more'\n" +
" dir('subdir') {stash 'whatever'}\n" +
"}\n" +
"node {\n" +
" dir('elsewhere') {\n" +
" unstash 'whatever'\n" +
" echo \"got fname: ${readFile 'fname'} other: ${readFile 'other'}\"\n" +
" }\n" +
" writeFile file: 'at-top', text: 'ignored'\n" +
" stash name: 'from-top', includes: 'elsewhere/', excludes: '**/other'\n" +
" semaphore 'ending'\n" +
"}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("ending/1", b);
assertEquals("{from-top={elsewhere/fname=whatever}, whatever={fname=whatever, other=more}}", StashManager.stashesOf(b).toString());
SemaphoreStep.success("ending/1", null);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("got fname: whatever other: more", b);
assertEquals("{}", StashManager.stashesOf(b).toString()); // TODO flake expected:<{[]}> but was:<{[from-top={elsewhere/fname=whatever}, whatever={fname=whatever, other=more}]}>
}
示例8: testAllowEmpty
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Issue("JENKINS-37327")
@Test public void testAllowEmpty() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" stash name: 'whatever', allowEmpty: true\n" +
" semaphore 'ending'\n" +
"}\n"
, true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("ending/1", b);
assertEquals("{whatever={}}", StashManager.stashesOf(b).toString());
SemaphoreStep.success("ending/1", null);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("Stashed 0 file(s)", b);
assertEquals("{}", StashManager.stashesOf(b).toString());
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("stash"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("whatever", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}
示例9: testDefaultJenkinsFileLoadFromWorkspace
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test
public void testDefaultJenkinsFileLoadFromWorkspace() throws Exception {
GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
ConfigFileStore store = globalConfigFiles.get();
Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
"semaphore 'wait'; node {checkout scm; load 'Jenkinsfile'}");
store.save(config);
sampleGitRepo.init();
sampleGitRepo.write("Jenkinsfile", "echo readFile('file')");
sampleGitRepo.git("add", "Jenkinsfile");
sampleGitRepo.write("file", "initial content");
sampleGitRepo.git("commit", "--all", "--message=flow");
WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
new DefaultBranchPropertyStrategy(new BranchProperty[0])));
WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
SemaphoreStep.waitForStart("wait/1", null);
WorkflowRun b1 = p.getLastBuild();
assertNotNull(b1);
assertEquals(1, b1.getNumber());
SemaphoreStep.success("wait/1", null);
r.assertLogContains("initial content", r.waitForCompletion(b1));
}
示例10: catchErrors
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void catchErrors() throws Exception {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" waitUntil {\n" +
" try {\n" +
" readFile 'flag'\n" +
" true\n" +
// Note that catching a specific type verifies JENKINS-26164:
" } catch (FileNotFoundException x) {\n" +
" // x.printStackTrace()\n" +
" semaphore 'wait'\n" +
" false\n" +
" }\n" +
" }\n" +
"}\n" +
"echo 'finished waiting'", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b);
story.j.jenkins.getWorkspaceFor(p).child("flag").write("", null);
SemaphoreStep.success("wait/1", null);
story.j.assertLogContains("finished waiting", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
}
});
}