Search in sources :

Example 6 with SelfPromotionCondition

use of hudson.plugins.promoted_builds.conditions.SelfPromotionCondition in project promoted-builds-plugin by jenkinsci.

the class JobDslPromotionProcessConverterTest method testShouldGenerateValidXml.

@Test
public void testShouldGenerateValidXml() throws Exception {
    // Given
    JobDslPromotionProcess pp = new JobDslPromotionProcess();
    //Conditions
    List<PromotionCondition> conditions = new ArrayList<PromotionCondition>();
    conditions.add(new SelfPromotionCondition(true));
    //BuildSteps
    List<Node> buildSteps = new ArrayList<Node>();
    Node node = new Node(null, "hudson.tasks.Shell");
    Node subNode = new Node(node, "command");
    buildSteps.add(node);
    subNode.setValue("echo hello;");
    Node node2 = new Node(null, "hudson.plugins.parameterizedtrigger.TriggerBuilder");
    Node subNode2 = new Node(node2, "configs");
    Node subsubNode2 = new Node(subNode2, "hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig");
    Node subsubsubNode2a = new Node(subsubNode2, "projects");
    subsubsubNode2a.setValue("anoter-project");
    Node subsubsubNode2b = new Node(subsubNode2, "condition");
    subsubsubNode2b.setValue("ALWAYS");
    buildSteps.add(node2);
    pp.setBuildSteps(buildSteps);
    pp.setConditions(conditions);
    // When
    XSTREAM.registerConverter(new JobDslPromotionProcessConverter(XSTREAM.getMapper(), XSTREAM.getReflectionProvider()));
    String xml = XSTREAM.toXML(pp);
    // Then
    assertNotNull(xml);
    System.out.println(xml);
    assertTrue(StringUtils.contains(xml, "hudson.plugins.promoted__builds.PromotionProcess"));
}
Also used : Node(groovy.util.Node) ArrayList(java.util.ArrayList) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) PromotionCondition(hudson.plugins.promoted_builds.PromotionCondition) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) Test(org.junit.Test)

Example 7 with SelfPromotionCondition

use of hudson.plugins.promoted_builds.conditions.SelfPromotionCondition in project promoted-builds-plugin by jenkinsci.

the class PromotionContext method conditions.

public void conditions(Closure<?> conditionClosure) {
    // delegate to ConditionsContext
    ConditionsContext conditionContext = new ConditionsContext(dslEnvironment);
    executeInContext(conditionClosure, conditionContext);
    if (conditionContext.isSelfPromotion()) {
        conditions.add(new SelfPromotionCondition(conditionContext.isEvenIfUnstable()));
    }
    if (conditionContext.isParameterizedSelfPromotion()) {
        conditions.add(new ParameterizedSelfPromotionCondition(conditionContext.isEvenIfUnstableParameterized(), conditionContext.getParameterName(), conditionContext.getParameterValue()));
    }
    if (conditionContext.isManual()) {
        JobDslManualCondition condition = new JobDslManualCondition();
        condition.setUsers(conditionContext.getUsers());
        if (conditionContext.getParams() != null) {
            condition.setParameterDefinitionNodes(conditionContext.getParams().values());
        }
        conditions.add(condition);
    }
    if (conditionContext.isReleaseBuild()) {
        conditions.add(new ReleasePromotionCondition());
    }
    if (conditionContext.isDownstreamPass()) {
        conditions.add(new DownstreamPassCondition(conditionContext.getJobs(), conditionContext.isEvenIfUnstableDownstream()));
    }
    if (conditionContext.isUpstreamPromotion()) {
        conditions.add(new UpstreamPromotionCondition(conditionContext.getPromotionNames()));
    }
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) UpstreamPromotionCondition(hudson.plugins.promoted_builds.conditions.UpstreamPromotionCondition) ParameterizedSelfPromotionCondition(hudson.plugins.promoted_builds.conditions.ParameterizedSelfPromotionCondition) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) ParameterizedSelfPromotionCondition(hudson.plugins.promoted_builds.conditions.ParameterizedSelfPromotionCondition)

Example 8 with SelfPromotionCondition

use of hudson.plugins.promoted_builds.conditions.SelfPromotionCondition in project promoted-builds-plugin by jenkinsci.

the class PromotedBuildRebuildParameterProviderTest method testRebuild.

@Test
public void testRebuild() throws Exception {
    // job with promotion process
    FreeStyleProject p1 = j.createFreeStyleProject("promojob");
    // setup promotion process
    JobPropertyImpl promotion = new JobPropertyImpl(p1);
    p1.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new SelfPromotionCondition(false));
    // build it
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p1.scheduleBuild2(0));
    j.waitUntilNoActivity();
    // verify that promotion happened
    Assert.assertSame(proc.getBuilds().getLastBuild().getTarget(), b1);
    // job with parameter
    FreeStyleProject p2 = j.createFreeStyleProject("paramjob");
    // add promoted build param
    p2.addProperty(new ParametersDefinitionProperty(new PromotedBuildParameterDefinition("var", "promojob", "promo", "promoted build param to test rebuild")));
    // build with parameter
    FreeStyleBuild b2 = j.assertBuildStatusSuccess(p2.scheduleBuild2(0));
    // validate presence of parameter
    ParametersAction a1 = b2.getAction(ParametersAction.class);
    Assert.assertNotNull(a1);
    Assert.assertFalse(a1.getParameters().isEmpty());
    ParameterValue v1 = a1.getParameter("var");
    Assert.assertTrue(v1 instanceof PromotedBuildParameterValue);
    PromotedBuildParameterValue pbpv1 = (PromotedBuildParameterValue) v1;
    Assert.assertEquals(b1.getNumber(), pbpv1.getRun().getNumber());
    // rebuild it
    JenkinsRule.WebClient wc = j.createWebClient();
    HtmlPage page = wc.getPage(b2, "rebuild");
    HtmlForm form = page.getFormByName("config");
    j.submit(form);
    j.waitUntilNoActivity();
    // validate presence of parameter
    FreeStyleBuild rebuild = p2.getLastBuild();
    j.assertBuildStatusSuccess(rebuild);
    Assert.assertNotEquals(b2.getNumber(), rebuild.getNumber());
    ParametersAction a2 = rebuild.getAction(ParametersAction.class);
    Assert.assertNotNull(a2);
    Assert.assertFalse(a2.getParameters().isEmpty());
    ParameterValue v2 = a2.getParameter("var");
    Assert.assertTrue(v2 instanceof PromotedBuildParameterValue);
    PromotedBuildParameterValue pbpv2 = (PromotedBuildParameterValue) v2;
    Assert.assertEquals(b1.getNumber(), pbpv2.getRun().getNumber());
}
Also used : PromotedBuildParameterValue(hudson.plugins.promoted_builds.parameters.PromotedBuildParameterValue) PromotedBuildParameterValue(hudson.plugins.promoted_builds.parameters.PromotedBuildParameterValue) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) PromotedBuildParameterDefinition(hudson.plugins.promoted_builds.parameters.PromotedBuildParameterDefinition) Test(org.junit.Test)

Aggregations

SelfPromotionCondition (hudson.plugins.promoted_builds.conditions.SelfPromotionCondition)8 Test (org.junit.Test)7 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)4 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)4 InheritanceProjectsPair (hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair)4 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)3 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)3 Promotion (hudson.plugins.promoted_builds.Promotion)3 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 Node (groovy.util.Node)1 FreeStyleProject (hudson.model.FreeStyleProject)1 ParametersAction (hudson.model.ParametersAction)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 StringParameterDefinition (hudson.model.StringParameterDefinition)1 StringParameterValue (hudson.model.StringParameterValue)1 PromotionCondition (hudson.plugins.promoted_builds.PromotionCondition)1 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)1