Search in sources :

Example 1 with BuildTrigger

use of hudson.tasks.BuildTrigger in project promoted-builds-plugin by jenkinsci.

the class DownstreamPassConditionTest method shouldEvaluateUpstreamRecursively.

@Test
@Bug(7739)
public void shouldEvaluateUpstreamRecursively() throws Exception {
    final FreeStyleProject job1 = j.createFreeStyleProject("job1");
    final FreeStyleProject job2 = j.createFreeStyleProject("job2");
    final FreeStyleProject job3 = j.createFreeStyleProject("job3");
    final JobPropertyImpl property = new JobPropertyImpl(job1);
    job1.addProperty(property);
    final PromotionProcess process = property.addProcess("promotion");
    process.conditions.add(new DownstreamPassCondition(job3.getFullName()));
    job1.getPublishersList().add(new BuildTrigger(job2.getFullName(), Result.SUCCESS));
    job2.getPublishersList().add(new BuildTrigger(job3.getFullName(), Result.SUCCESS));
    j.jenkins.rebuildDependencyGraph();
    final FreeStyleBuild run1 = j.buildAndAssertSuccess(job1);
    j.waitUntilNoActivity();
    j.assertBuildStatusSuccess(job2.getLastBuild());
    j.waitUntilNoActivity();
    final FreeStyleBuild run3 = j.assertBuildStatusSuccess(job3.getLastBuild());
    j.waitUntilNoActivity();
    assertEquals("fingerprint relation", run3.getUpstreamRelationship(job1), -1);
    assertFalse("no promotion process", process.getBuilds().isEmpty());
    final PromotedBuildAction action = run1.getAction(PromotedBuildAction.class);
    assertNotNull("no promoted action", action);
    final Status promotion = action.getPromotion("promotion");
    assertNotNull("promotion not found", promotion);
    assertTrue("promotion not successful", promotion.isPromotionSuccessful());
}
Also used : Status(hudson.plugins.promoted_builds.Status) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Example 2 with BuildTrigger

use of hudson.tasks.BuildTrigger in project promoted-builds-plugin by jenkinsci.

the class DownstreamPassConditionInheritanceTest method shouldEvaluateUpstreamRecursively.

@Test
@Bug(7739)
public void shouldEvaluateUpstreamRecursively() throws Exception {
    final InheritanceProjectsPair pair1 = j.createInheritanceProjectDerivedWithBase();
    final InheritanceProjectsPair pair2 = j.createInheritanceProjectDerivedWithBase();
    final InheritanceProjectsPair pair3 = j.createInheritanceProjectDerivedWithBase();
    final JobPropertyImpl property = new JobPropertyImpl(pair1.getBase());
    pair1.getBase().addProperty(property);
    final PromotionProcess process = property.addProcess("promotion");
    process.conditions.add(new DownstreamPassCondition(pair3.getDerived().getFullName()));
    pair1.getDerived().getPublishersList().add(new BuildTrigger(pair2.getDerived().getFullName(), Result.SUCCESS));
    pair2.getDerived().getPublishersList().add(new BuildTrigger(pair3.getDerived().getFullName(), Result.SUCCESS));
    j.jenkins.rebuildDependencyGraph();
    final InheritanceBuild run1 = j.buildAndAssertSuccess(pair1.getDerived());
    j.assertBuildStatusSuccess(run1);
    j.waitUntilNoActivity();
    j.assertBuildStatusSuccess(pair2.getDerived().getLastBuild());
    j.waitUntilNoActivity();
    final InheritanceBuild run3 = j.assertBuildStatusSuccess(pair3.getDerived().getLastBuild());
    j.waitUntilNoActivity();
    //We cannot assume that the process will contain builds because the process added to base project is different to the one in derived. 
    JobPropertyImpl jobProperty = pair1.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53 
                because that version of the plugin uses inheritance only for certain predefined cases: 
                -specific methods on the call stack
                -url paths.
                This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
               */
    IMode.INHERIT_FORCED);
    assertNotNull("derived jobProperty is null", jobProperty);
    PromotionProcess processDerived = jobProperty.getItem("promotion");
    assertEquals("fingerprint relation", run3.getUpstreamRelationship(pair1.getDerived()), -1);
    assertFalse("no promotion process", processDerived.getBuilds().isEmpty());
    final PromotedBuildAction action = run1.getAction(PromotedBuildAction.class);
    assertNotNull("no promoted action", action);
    final Status promotion = action.getPromotion("promotion");
    assertNotNull("promotion not found", promotion);
    assertTrue("promotion not successful", promotion.isPromotionSuccessful());
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) Status(hudson.plugins.promoted_builds.Status) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) BuildTrigger(hudson.tasks.BuildTrigger) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Example 3 with BuildTrigger

use of hudson.tasks.BuildTrigger in project hudson-2.x by hudson.

the class AbstractProject method doConfigSubmit.

@Override
public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
    super.doConfigSubmit(req, rsp);
    updateTransientActions();
    Set<AbstractProject> upstream = Collections.emptySet();
    if (req.getParameter("pseudoUpstreamTrigger") != null) {
        upstream = new HashSet<AbstractProject>(Items.fromNameList(req.getParameter("upstreamProjects"), AbstractProject.class));
    }
    // dependency setting might have been changed by the user, so rebuild.
    Hudson.getInstance().rebuildDependencyGraph();
    for (AbstractProject<?, ?> p : Hudson.getInstance().getAllItems(AbstractProject.class)) {
        // Don't consider child projects such as MatrixConfiguration:
        if (!p.isConfigurable())
            continue;
        boolean isUpstream = upstream.contains(p);
        synchronized (p) {
            // does 'p' include us in its BuildTrigger? 
            DescribableList<Publisher, Descriptor<Publisher>> pl = p.getPublishersList();
            BuildTrigger trigger = pl.get(BuildTrigger.class);
            List<AbstractProject> newChildProjects = trigger == null ? new ArrayList<AbstractProject>() : trigger.getChildProjects();
            if (isUpstream) {
                if (!newChildProjects.contains(this))
                    newChildProjects.add(this);
            } else {
                newChildProjects.remove(this);
            }
            if (newChildProjects.isEmpty()) {
                pl.remove(BuildTrigger.class);
            } else {
                // here, we just need to replace the old one with the new one,
                // but there was a regression (we don't know when it started) that put multiple BuildTriggers
                // into the list.
                // for us not to lose the data, we need to merge them all.
                List<BuildTrigger> existingList = pl.getAll(BuildTrigger.class);
                BuildTrigger existing;
                switch(existingList.size()) {
                    case 0:
                        existing = null;
                        break;
                    case 1:
                        existing = existingList.get(0);
                        break;
                    default:
                        pl.removeAll(BuildTrigger.class);
                        Set<AbstractProject> combinedChildren = new HashSet<AbstractProject>();
                        for (BuildTrigger bt : existingList) combinedChildren.addAll(bt.getChildProjects());
                        existing = new BuildTrigger(new ArrayList<AbstractProject>(combinedChildren), existingList.get(0).getThreshold());
                        pl.add(existing);
                        break;
                }
                if (existing != null && existing.hasSame(newChildProjects))
                    // no need to touch
                    continue;
                pl.replace(new BuildTrigger(newChildProjects, existing == null ? Result.SUCCESS : existing.getThreshold()));
            }
            BuildTrigger buildTrigger = pl.get(BuildTrigger.class);
            CascadingUtil.getExternalProjectProperty(p, BUILD_TRIGGER_PROPERTY_NAME).setValue(buildTrigger);
        }
    }
    // notify the queue as the project might be now tied to different node
    Hudson.getInstance().getQueue().scheduleMaintenance();
    // this is to reflect the upstream build adjustments done above
    Hudson.getInstance().rebuildDependencyGraph();
}
Also used : ArrayList(java.util.ArrayList) Publisher(hudson.tasks.Publisher) BuildTrigger(hudson.tasks.BuildTrigger) BuildStepDescriptor(hudson.tasks.BuildStepDescriptor) BuildWrapperDescriptor(hudson.tasks.BuildWrapperDescriptor) TriggerDescriptor(hudson.triggers.TriggerDescriptor) IAbstractProject(org.hudsonci.api.model.IAbstractProject) HashSet(java.util.HashSet)

Example 4 with BuildTrigger

use of hudson.tasks.BuildTrigger in project promoted-builds-plugin by jenkinsci.

the class PromotionProcessTest method testPromotionWithoutFingerprint.

/**
     * Tests a promotion induced by the pseudo upstream/downstream cause relationship
     */
public void testPromotionWithoutFingerprint() throws Exception {
    FreeStyleProject up = createFreeStyleProject("up");
    FreeStyleProject down = createFreeStyleProject();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(up);
    up.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    // trigger downstream automatically to create relationship
    up.getPublishersList().add(new BuildTrigger(down.getName(), Result.SUCCESS));
    hudson.rebuildDependencyGraph();
    // this is the downstream job
    down.getBuildersList().add(new Shell(// expr exits with non-zero status if result is zero
    "expr $BUILD_NUMBER % 2 - 1\n"));
    // not yet promoted while the downstream is failing
    FreeStyleBuild up1 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    waitForCompletion(down, 1);
    assertEquals(0, proc.getBuilds().size());
    // do it one more time and this time it should work
    FreeStyleBuild up2 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    waitForCompletion(down, 2);
    assertEquals(1, proc.getBuilds().size());
    {
        // verify that it promoted the right stuff
        Promotion pb = proc.getBuilds().get(0);
        assertSame(pb.getTarget(), up2);
        PromotedBuildAction badge = (PromotedBuildAction) up2.getBadgeActions().get(0);
        assertTrue(badge.contains(proc));
    }
}
Also used : Shell(hudson.tasks.Shell) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject)

Aggregations

BuildTrigger (hudson.tasks.BuildTrigger)4 FreeStyleBuild (hudson.model.FreeStyleBuild)2 FreeStyleProject (hudson.model.FreeStyleProject)2 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)2 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)2 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)2 Status (hudson.plugins.promoted_builds.Status)2 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)2 Test (org.junit.Test)2 Bug (org.jvnet.hudson.test.Bug)2 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)1 InheritanceProjectsPair (hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair)1 BuildStepDescriptor (hudson.tasks.BuildStepDescriptor)1 BuildWrapperDescriptor (hudson.tasks.BuildWrapperDescriptor)1 Publisher (hudson.tasks.Publisher)1 Shell (hudson.tasks.Shell)1 TriggerDescriptor (hudson.triggers.TriggerDescriptor)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IAbstractProject (org.hudsonci.api.model.IAbstractProject)1