本文整理汇总了Java中org.jenkinsci.plugins.workflow.job.WorkflowJob.setDefinition方法的典型用法代码示例。如果您正苦于以下问题:Java WorkflowJob.setDefinition方法的具体用法?Java WorkflowJob.setDefinition怎么用?Java WorkflowJob.setDefinition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jenkinsci.plugins.workflow.job.WorkflowJob
的用法示例。
在下文中一共展示了WorkflowJob.setDefinition方法的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: 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));
}
示例3: 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));
}
示例4: 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));
}
示例5: 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);
}
示例6: specialStatus
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的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());
*/
}
示例7: 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);
}
示例8: 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);
}
示例9: maven_build_on_master_with_no_generated_jar_succeeds
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
/**
* JENKINS-43678
*/
@Test
public void maven_build_on_master_with_no_generated_jar_succeeds() throws Exception {
loadMavenJarProjectInGitRepo(this.gitRepoRule);
String pipelineScript = "node('master') {\n" +
" git($/" + gitRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn test'\n" +
" }\n" +
"}";
WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "test-on-master");
pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
// don't try to archive the artifact as it has not been generated
jenkinsRule.assertLogNotContains("under jenkins/mvn/test/mono-module-maven-app/0.1-SNAPSHOT/mono-module-maven-app-0.1-SNAPSHOT.jar", build);
Collection<String> artifactsFileNames = TestUtils.artifactsToArtifactsFileNames(build.getArtifacts());
assertThat(artifactsFileNames, hasItems("mono-module-maven-app-0.1-SNAPSHOT.pom"));
assertThat(build.getArtifacts().toString(), build.getArtifacts().size(), is(1));
}
示例10: testWorkflow
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
/**
* Also applicable for workflow jobs.
*/
@Issue("JENKINS-30357")
@Test
public void testWorkflow() throws Exception {
FreeStyleProject jobToSelect = j.createFreeStyleProject();
Run runToSelect = j.assertBuildStatusSuccess(jobToSelect.scheduleBuild2(0));
WorkflowJob selecter = createWorkflowJob();
ParameterDefinition paramDef = new StringParameterDefinition(
"SELECTOR", "<StatusRunSelector><buildStatus>STABLE</buildStatus></StatusRunSelector>"
);
selecter.addProperty(new ParametersDefinitionProperty(paramDef));
selecter.setDefinition(new CpsFlowDefinition(String.format("" +
"def runWrapper = selectRun job: '%s', " +
" selector: [$class: 'ParameterizedRunSelector', parameterName: '${SELECTOR}'] \n" +
"assert(runWrapper.id == '%s')", jobToSelect.getFullName(), runToSelect.getId())));
j.assertBuildStatusSuccess(selecter.scheduleBuild2(0));
}
示例11: testImmediateValue
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
/**
* Also accepts immediate value.
*/
@Test
public void testImmediateValue() throws Exception {
// Prepare an artifact to be copied.
FreeStyleProject jobToSelect = j.createFreeStyleProject();
Run runToSelect = j.assertBuildStatusSuccess(jobToSelect.scheduleBuild2(0));
WorkflowJob selecter = createWorkflowJob();
selecter.setDefinition(new CpsFlowDefinition(String.format("" +
"def runWrapper = selectRun job: '%s', " +
" selector: [$class: 'ParameterizedRunSelector', parameterName: '${SELECTOR}'] \n" +
"assert(runWrapper.id == '%s')", jobToSelect.getFullName(), runToSelect.getId())));
j.assertBuildStatusSuccess(selecter.scheduleBuild2(
0,
null,
new ParametersAction(new StringParameterValue(
"SELECTOR", "<StatusRunSelector><buildStatus>STABLE</buildStatus></StatusRunSelector>"
))
));
}
示例12: testIsSelectableWithDefault
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
@Test
public void testIsSelectableWithDefault() throws Exception {
WorkflowJob selecter = j.jenkins.createProject(
WorkflowJob.class,
RandomStringUtils.randomAlphanumeric(7)
);
selecter.addProperty(new ParametersDefinitionProperty(
new RunFilterParameter(
"FILTER",
"description",
new SavedRunFilter()
)
));
selecter.setDefinition(new CpsFlowDefinition(String.format(
"def runWrapper = selectRun"
+ " job: '%s',"
+ " filter: [$class: 'ParameterizedRunFilter', parameter: '${FILTER}'],"
+ " verbose: true;"
+ "assert(runWrapper.id == '%s')",
jobToSelect.getFullName(),
runToSelect1.getId()
)));
j.assertBuildStatusSuccess(selecter.scheduleBuild2(0));
}
示例13: testSecretWithSpace
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
@Test
public void testSecretWithSpace() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), secretCredentialWithSpace());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testSecretWithSpace");
p.setDefinition(new CpsFlowDefinition(loadResource("mockedKubectl.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains("with-space", b);
r.assertLogNotContains("s3cr3t", b);
}
示例14: testUsernamePasswordWithSpace
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
@Test
public void testUsernamePasswordWithSpace() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredentialWithSpace());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testUsernamePasswordWithSpace");
p.setDefinition(new CpsFlowDefinition(loadResource("mockedKubectl.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains("with-passwordspace", b);
r.assertLogNotContains("s3cr3t", b);
}
示例15: runAndGetWorkspaceDir
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
/**
* Runs the given flow and returns the workspace used.
* @param flow a flow definition.
* @return the workspace used.
*/
private String runAndGetWorkspaceDir(String flow) throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(flow));
r.assertBuildStatusSuccess(p.scheduleBuild2(0));
FilePath ws = r.jenkins.getWorkspaceFor(p);
String workspace = ws.getRemote();
Assert.assertNotNull("Unable to locate workspace", workspace);
return workspace;
}