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

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

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

Jenkins.createProject介绍

[英]Creates a new job.

This version infers the descriptor from the type of the top-level item.
[中]创建一个新的工作。
此版本根据顶级项的类型推断描述符。

代码示例

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

/**
* Tests the ability to execute a user defined closure with no arguments
*/
@Test public void userDefinedClosure0ArgsExecution() throws Exception {
   WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
   p.setDefinition(new CpsFlowDefinition("binding.setVariable(\"my_closure\", { echo \"my closure!\" })\n my_closure() ", false));
   WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
   r.assertLogContains("my closure!", b); 
}

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

/**
* Tests the ability to execute a user defined closure with one arguments
*/
@Test public void userDefinedClosure1ArgInvocationExecution() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("my_closure = { String message -> \n" +
                     "  echo message \n" +
                     "}\n" + 
                     "my_closure(\"my message!\") ", false));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("my message!", b); 
}

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

/**
* Tests untyped arguments 
*/
@Test public void userDefinedClosureUntypedArgInvocationExecution() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("my_closure = { a , b -> \n" +
                         "  echo \"my message is ${a} and ${b}\" \n" +
                         "}\n" +
                         "my_closure(\"string1\" ,2)",false));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("my message is string1 and 2", b);
}

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

@Test public void quotedStep() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("'echo' 'Hello1'\n" +
                     "\"echo\" 'Hello2'", true));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("Hello1", b);
  r.assertLogContains("Hello2", b);
}

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

@Test public void ambiguousStepsRespectOrdinal() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("ambiguousEcho 'HeLlO'\n", true));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("HELLO", b);
  r.assertLogContains("Warning: Invoking ambiguous Pipeline Step", b);
  r.assertLogContains("any of the following steps: [" + AmbiguousEchoUpperStep.class.getName() + ", " + AmbiguousEchoLowerStep.class.getName() + "]", b);
}

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

/**
* Tests the ability to execute a user defined closure with 2 arguments
*/
@Test public void userDefinedClosure2ArgInvocationExecution() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("my_closure = { String message1, String message2 -> \n" +
                     "  echo \"my message is ${message1} and ${message2}\" \n" +
                     "}\n" + 
                     "my_closure(\"string1\", \"string2\") ", false));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("my message is string1 and string2", b); 
}

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

@Test public void fullyQualifiedStep() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("'org.jenkinsci.plugins.workflow.steps.EchoStep' 'Hello, world!'", true));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("Hello, world!", b);
}

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

/**
* Tests the ability to execute a user defined closure
*/
@Test public void userDefinedClosureInvocationExecution() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("binding[\"my_closure\"] = { \n" +
                     " sleep 1 \n" + 
                     " echo \"my closure!\" \n" + 
                     "}\n" + 
                     "my_closure() ", false));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("my closure!", b); 
}

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

@Test
public void basics() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition(
    "node {\n" +
    "  writeFile text: 'println(21*2)', file: 'test.groovy'\n" +
    "  println 'something printed'\n" +// make sure that 'println' in groovy script works
    "  load 'test.groovy'\n" +
    "}", true));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("something printed", b);
  r.assertLogContains("42", b);
}

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

@Test public void overrideFunction() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("echo 'this came from a step'", true));
  r.assertLogContains("this came from a step", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
  p.setDefinition(new CpsFlowDefinition("def echo(s) {println s.toUpperCase()}\necho 'this came from my own function'\nsteps.echo 'but this is still from a step'", true));
  WorkflowRun b2 = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("THIS CAME FROM MY OWN FUNCTION", b2);
  r.assertLogContains("but this is still from a step", b2);
}

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

@Issue("JENKINS-29922")
@Test
public void nonexistentFunctions() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("nonexistent()", true));
  WorkflowRun b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
  r.assertLogContains("nonexistent", b);
  r.assertLogContains("wrapInCurve", b);
  r.assertLogContains("polygon", b);
}

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

/**
 * "evaluate" call is supposed to yield a value
 */
@Test
public void evaluationResult() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition(
      "node {\n" +
      "  writeFile text: '21*2', file: 'test.groovy'\n" +
      "  def o = load('test.groovy')\n" +
      "  println 'output=' + o\n" +
      "}", false));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("output=42", b);
}

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

@Issue("JENKINS-43934")
@Test public void flattenGString() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("def message = myJoin(['the', /${'message'.toLowerCase(Locale.ENGLISH)}/]); echo(/What is $message?/)", true));
  r.assertLogContains("What is the message?", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
public static class MyJoinStep extends Step {

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

/**
 * Split arguments between meta step and state
 */
@Issue("JENKINS-29922")
@Test
public void dollar_class_must_die3() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "die3");
  p.setDefinition(new CpsFlowDefinition("nevada()", true));
  r.assertLogContains("All For Our Country", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

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

/**
 * Tests the ability to execute a step with an unnamed monomorphic list argument.
 */
@Issue("JENKINS-29711")
@Test
public void monomorphicList() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "monList");
  p.setDefinition(new CpsFlowDefinition("monomorphListStep([[firstArg:'one', secondArg:'two'], [firstArg:'three', secondArg:'four']])", true));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("First arg: one, second arg: two", b);
  r.assertLogContains("First arg: three, second arg: four", b);
}

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

@Issue("JENKINS-29711")
@Test
public void monomorphicListWithSymbol() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "monListSymbol");
  p.setDefinition(new CpsFlowDefinition("monomorphListSymbolStep([monomorphSymbol(firstArg: 'one', secondArg: 'two'), monomorphSymbol(firstArg: 'three', secondArg: 'four')])", true));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("First arg: one, second arg: two", b);
  r.assertLogContains("First arg: three, second arg: four", b);
}

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

@Issue("JENKINS-38037")
@Test
public void metaStepSyntaxForDataBoundSetters() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "metaStepSyntaxForDataBoundSetters");
  p.setDefinition(new CpsFlowDefinition("multiShape(count: 2, name: 'pentagon') { echo 'Multiple shapes' }", true));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("wrapping in a group of 2 instances of pentagon", b);
  r.assertLogContains("Multiple shapes", b);
}

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

@Test public void fullyQualifiedAmbiguousStep() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition(
      "'org.jenkinsci.plugins.workflow.testMetaStep.AmbiguousEchoLowerStep' 'HeLlO'\n" +
      "'org.jenkinsci.plugins.workflow.testMetaStep.AmbiguousEchoUpperStep' 'GoOdByE'", true));
  WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
  r.assertLogContains("hello", b);
  r.assertLogContains("GOODBYE", b);
  r.assertLogNotContains("Warning: Invoking ambiguous Pipeline Step", b);
}

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

@Issue("JENKINS-43934")
@Test public void flattenGString2() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(new CpsFlowDefinition("echo pops(pojo(/running #$BUILD_NUMBER/))", true));
  r.assertLogContains("running #1", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
public static class Pojo extends AbstractDescribableImpl<Pojo> {

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

/**
 * Single argument state
 */
@Issue("JENKINS-29922")
@Test
public void dollar_class_must_die_onearg() throws Exception {
  WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "die4");
  p.setDefinition(new CpsFlowDefinition("newYork 'Empire'", true));
  r.assertLogContains("The Empire State", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

相关文章

微信公众号

最新文章

更多

Jenkins类方法