本文整理汇总了Java中org.jenkinsci.plugins.workflow.job.WorkflowJob类的典型用法代码示例。如果您正苦于以下问题:Java WorkflowJob类的具体用法?Java WorkflowJob怎么用?Java WorkflowJob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WorkflowJob类属于org.jenkinsci.plugins.workflow.job包,在下文中一共展示了WorkflowJob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: junitResultArchiver
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test public void junitResultArchiver() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n"
+ " writeFile text: '''<testsuite name='a'><testcase name='a1'/><testcase name='a2'><error>a2 failed</error></testcase></testsuite>''', file: 'a.xml'\n"
+ " writeFile text: '''<testsuite name='b'><testcase name='b1'/><testcase name='b2'/></testsuite>''', file: 'b.xml'\n"
+ " junit '*.xml'\n"
+ "}", true));
WorkflowRun b = r.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get());
TestResultAction a = b.getAction(TestResultAction.class);
assertNotNull(a);
assertEquals(4, a.getTotalCount());
assertEquals(1, a.getFailCount());
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("step"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("*.xml", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}
示例2: smokes
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test public void smokes() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'hello there'", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
List<LogAction> logActions = new ArrayList<LogAction>();
for (FlowNode n : new FlowGraphWalker(b.getExecution())) {
LogAction la = n.getAction(LogAction.class);
if (la != null) {
logActions.add(la);
}
}
assertEquals(1, logActions.size());
StringWriter w = new StringWriter();
logActions.get(0).getLogText().writeLogTo(0, w);
assertEquals("hello there", w.toString().trim());
Matcher m = Pattern.compile("hello there").matcher(JenkinsRule.getLog(b));
assertTrue("message printed once", m.find());
assertFalse("message not printed twice", m.find());
}
示例3: testBasicWithCa
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test
public void testBasicWithCa() throws Exception {
String encodedCertificate = new String(Base64.getEncoder().encode(CA_CERTIFICATE.getBytes()));
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredential());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testBasicWithCa");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("kubectl configuration cleaned up", b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("certificate-authority-data: " + encodedCertificate));
assertTrue(configDumpContent.contains("server: " + SERVER_URL));
}
示例4: testBasicWithoutCa
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test
public void testBasicWithoutCa() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredential());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testBasicWithoutCa");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("kubectl configuration cleaned up", b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("insecure-skip-tls-verify: true"));
assertTrue(configDumpContent.contains("server: " + SERVER_URL));
}
示例5: testUsernamePasswordCredentials
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test
public void testUsernamePasswordCredentials() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredentialWithSpace());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testUsernamePasswordCredentials");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains(PASSWORD_WITH_SPACE, b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("username: " + USERNAME_WITH_SPACE));
assertTrue(configDumpContent.contains("password: " + PASSWORD_WITH_SPACE));
}
示例6: testSecretCredentials
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test
public void testSecretCredentials() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), secretCredentialWithSpace());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testSecretCredentials");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains(PASSWORD_WITH_SPACE, b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("token: " + PASSWORD_WITH_SPACE));
}
示例7: argumentsToString
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Issue("JENKINS-45101")
@Test public void argumentsToString() 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" +
" wrap([$class: 'AnsiColorBuildWrapper', colorMapName: 'xterm']) {}\n" +
"}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), Predicates.and(new NodeStepTypePredicate("wrap"), new Predicate<FlowNode>() {
@Override public boolean apply(FlowNode n) {
return n instanceof StepStartNode && !((StepStartNode) n).isBody();
}
}));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("xterm", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}
});
}
示例8: simple
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的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)));
}
});
}
示例9: failure
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的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
}
});
}
示例10: basics
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test public void basics() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
boolean win = Functions.isWindows();
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
(win ? " bat 'echo hello > f1'\n" : " sh 'echo hello > f1'\n") +
" def text = readFile 'f1'\n" +
" text = text.toUpperCase()\n" +
" writeFile file: 'f2', text: text\n" +
(win ? " bat 'type f2'\n" : " sh 'cat f2'\n") +
"}", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("HELLO", b);
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("writeFile"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("f2", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}
示例11: shouldTestFileExistsStep
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test
public void shouldTestFileExistsStep() throws Exception
{
final WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" echo \"test.txt - FileExists: ${fileExists('test.txt')}\" \n" +
" writeFile file: 'test2.txt', text:'content of file' \n" +
" echo \"test2.txt - FileExists: ${fileExists('test2.txt')}\" \n" +
"}"));
WorkflowRun run = p.scheduleBuild2(0).get();
r.assertLogContains("test.txt - FileExists: false", run);
r.assertLogContains("test2.txt - FileExists: true", run);
r.assertBuildStatusSuccess(run);
}
示例12: test_send
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test
public void test_send() throws Exception {
Mailbox.clearAll();
WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "workflow");
job.setDefinition(new CpsFlowDefinition("mail(to: '[email protected]', subject: 'Hello friend', body: 'Missing you!');", true));
WorkflowRun b = r.assertBuildStatusSuccess(job.scheduleBuild2(0));
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("mail"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals("Hello friend", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
Mailbox mailbox = Mailbox.get("[email protected]");
Assert.assertEquals(1, mailbox.getNewMessageCount());
Message message = mailbox.get(0);
Assert.assertEquals("Hello friend", message.getSubject());
Assert.assertEquals("Missing you!", ((MimeMultipart)message.getContent()).getBodyPart(0).getContent().toString());
}
示例13: abortShouldNotRetry
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的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);
}
示例14: archive
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
/**
* Archive and unarchive file
*/
@Test
public void archive() throws Exception {
// job setup
WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo");
foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList(
"node {",
" writeFile text: 'hello world', file: 'msg'",
" archive 'm*'",
" unarchive(mapping:['msg':'msg.out'])",
" archive 'msg.out'",
"}"), "\n")));
// get the build going, and wait until workflow pauses
WorkflowRun b = j.assertBuildStatusSuccess(foo.scheduleBuild2(0).get());
VirtualFile archivedFile = b.getArtifactManager().root().child("msg.out");
assertTrue(archivedFile.exists());
assertEquals("hello world", IOUtils.toString(archivedFile.open()));
j.assertLogContains(Messages.ArtifactArchiverStepExecution_Deprecated(), b);
}
示例15: unarchiveDir
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入依赖的package包/类
@Test public void unarchiveDir() throws Exception {
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList(
"node {",
" writeFile text: 'one', file: 'a/1'; writeFile text: 'two', file: 'a/b/2'",
" archive 'a/'",
" dir('new') {",
" unarchive mapping: ['a/' : '.']",
" echo \"${readFile 'a/1'}/${readFile 'a/b/2'}\"",
" }",
"}"), "\n")));
WorkflowRun b = j.assertBuildStatusSuccess(p.scheduleBuild2(0).get());
VirtualFile archivedFile = b.getArtifactManager().root().child("a/b/2");
assertTrue(archivedFile.exists());
assertEquals("two", IOUtils.toString(archivedFile.open()));
j.assertLogContains("one/two", b);
}