Skip to content
Permalink
Browse files

[JENKINS-30795] Made it possible to rebuild last baseline when previo…

…us baseline failed
  • Loading branch information
MadsNielsen committed Oct 19, 2015
1 parent e1501b5 commit 1e72ba204308a0391cc7ec3223d4ad7eb70936cd
@@ -442,14 +442,14 @@
<dependency>
<groupId>net.praqma</groupId>
<artifactId>cool</artifactId>
<version>0.6.45</version>
<version>0.6.47</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>net.praqma</groupId>
<artifactId>cool</artifactId>
<version>0.6.45</version>
<version>0.6.47</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
@@ -168,7 +168,8 @@ public Status invoke( File workspace, VirtualChannel channel ) throws IOExceptio
* break method here
*/
hudsonOut.println( CCUCMNotifier.logShortPrefix+" Could not promote baseline " + sourcebaseline.getShortname() + ". " + e.getMessage() );
logger.warning( "Could not promote baseline. " + e.getMessage() );
logger.warning(String.format("Could not promote baseline: %s", sourcebaseline.getShortname()));
logger.log(Level.WARNING, "Unable to promote baseline. Recommended is disabled.", e);
}
}

@@ -5,6 +5,7 @@
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.*;
import hudson.model.Cause.UserIdCause;
import hudson.scm.ChangeLogParser;
import hudson.scm.PollingResult;
import hudson.scm.SCMDescriptor;
@@ -276,8 +277,8 @@ public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath w
} catch (CCUCMException e) {

logger.warning(e.getMessage());
/* If the promotion level is not set, ANY, use the last found Baseline */
if (mode.getPromotionLevel() == null) {
/* If the promotion level is not set, ANY, use the last found Baseline, or the manual build was triggered */
if (mode.getPromotionLevel() == null || build.getCause(UserIdCause.class) != null) {
logger.fine("Configured to use the latest always.");
CCUCMBuildAction last = getLastAction(build.getProject());
if (last != null) {
@@ -6,6 +6,7 @@
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import hudson.slaves.DumbSlave;
import hudson.triggers.SCMTrigger;

import java.io.File;
import java.io.IOException;
@@ -173,9 +174,15 @@ public FreeStyleProject getProject() throws IOException {
System.out.println( " * Swipe : " + swipe );
System.out.println( " * Trim : " + trim );
System.out.println( " * Discard : " + discard);
System.out.println( " * Project name : " + name);
System.out.println( " * Project type : " + projectClass.getSimpleName() );
System.out.println( "============================================" );

FreeStyleProject project = Jenkins.getInstance().createProject( projectClass, name );
Jenkins j = Jenkins.getInstance();

assert j != null : "Jenkins is null in this instance...should not be possible";

FreeStyleProject project = j.createProject( projectClass, name );
CCUCMScm scm = new CCUCMScm( component, "ALL", false, mode, stream, "successful", template, forceDeliver, recommend, tag, description, "", swipe, trim, discard );
project.setScm( scm );

@@ -291,8 +298,12 @@ public ProjectBuilder failBuild( boolean cancel ) {
this.fail = cancel;
return this;
}

public AbstractBuild build() throws ExecutionException, InterruptedException, IOException {
return build(new Cause.UserIdCause());
}

public AbstractBuild build() throws ExecutionException, InterruptedException, IOException {
public AbstractBuild build(Cause cause) throws ExecutionException, InterruptedException, IOException {

if( fail ) {
logger.info( "Failing " + project );
@@ -308,7 +319,7 @@ public AbstractBuild build() throws ExecutionException, InterruptedException, IO
action = new EnableLoggerAction( outputDir );
}

Future<? extends Build<?, ?>> futureBuild = project.scheduleBuild2( 0, new Cause.UserIdCause(), action );
Future<? extends Build<?, ?>> futureBuild = project.scheduleBuild2( 0, cause, action );

AbstractBuild build = futureBuild.get();

@@ -349,7 +360,7 @@ public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListe

AbstractBuild<?,?> build = null;
try {
build = project.scheduleBuild2(0, new Cause.UserIdCause(), action ).get();
build = project.scheduleBuild2(0, new SCMTrigger.SCMTriggerCause("SCM trigger by testing"), action ).get();
} catch ( Exception e ) {
if(!fail) {
logger.log(Level.SEVERE, "Build failed...it should not!", e);
@@ -7,6 +7,7 @@
import hudson.model.AbstractBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.triggers.SCMTrigger;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import net.praqma.hudson.test.SystemValidator;
@@ -118,7 +119,7 @@ public void testUseNewest() throws Exception {
.setMode(modeChild);

FreeStyleProject p = creator.getProject();
AbstractBuild<?,?> buildNewest = jenkins.getProjectBuilder(p).build();
AbstractBuild<?,?> buildNewest = jenkins.getProjectBuilder(p).build(new SCMTrigger.SCMTriggerCause("Trigger change for SCM test"));

//First build should be succes
SystemValidator validator = new SystemValidator(buildNewest)
@@ -128,7 +129,7 @@ public void testUseNewest() throws Exception {
validator.validate();

//Next build. Nothing to do
AbstractBuild<?,?> nothing = jenkins.getProjectBuilder(p).build();
AbstractBuild<?,?> nothing = jenkins.getProjectBuilder(p).build(new SCMTrigger.SCMTriggerCause("Trigger change for SCM test"));
SystemValidator validator2 = new SystemValidator(nothing)
.validateBuild(Result.NOT_BUILT);
validator2.validate();
@@ -3,7 +3,6 @@
import java.io.File;

import net.praqma.hudson.test.BaseTestClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

@@ -17,7 +16,6 @@
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import net.praqma.clearcase.ucm.view.UCMView;
import net.praqma.clearcase.util.ExceptionUtils;
import net.praqma.hudson.test.LoggerRule;
import net.praqma.hudson.test.SystemValidator;
import net.praqma.util.test.junit.TestDescription;

@@ -0,0 +1,75 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package net.praqma.hudson.test.integration.child;

import hudson.model.AbstractBuild;
import hudson.model.Cause;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
import net.praqma.clearcase.test.junit.ClearCaseRule;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Project;
import net.praqma.hudson.scm.pollingmode.PollChildMode;
import net.praqma.hudson.test.BaseTestClass;
import static net.praqma.hudson.test.BaseTestClass.jenkins;
import net.praqma.hudson.test.CCUCMRule;
import net.praqma.hudson.test.SystemValidator;
import net.praqma.util.test.junit.DescriptionRule;
import net.praqma.util.test.junit.TestDescription;
import org.junit.Rule;
import org.junit.Test;

/**
*
* @author Mads
*/
public class ManualTriggerIT extends BaseTestClass {

@Rule
public ClearCaseRule ccenv = new ClearCaseRule("ccucm");

@Rule
public DescriptionRule desc = new DescriptionRule();

@Test
@ClearCaseUniqueVobName(name = "manual-trigger")
@TestDescription(title = "Child polling, exhaust baseline build manually last build", text = "baseline available", configurations = {"Use newest = true"})
public void testManual() throws Exception {
//Create a new baseline
Baseline bl1 = ccenv.createNewDevStreamContents("one_dev").load();

//Create another
Baseline bl2 = ccenv.createNewDevStreamContents("one_dev").load();

PollChildMode modeChild = new PollChildMode("INITIAL");
modeChild.setNewest(true);
modeChild.setCreateBaseline(true);

CCUCMRule.ProjectCreator creator = new CCUCMRule.ProjectCreator("manual-" + ccenv.getUniqueName(), "_System@" + ccenv.getPVob(), "one_int@" + ccenv.getPVob())
.setMode(modeChild);


FreeStyleProject p = creator.getProject();
AbstractBuild<?,?> buildNewest = jenkins.getProjectBuilder(p).failBuild(true).build();

//First build we fail. That means no created baseline on source
SystemValidator validator = new SystemValidator(buildNewest)
.validateBuild(Result.FAILURE)
.validateBuiltBaseline(Project.PromotionLevel.REJECTED, bl2);
validator.validate();

//Reset promotion level
bl2.setPromotionLevel(Project.PromotionLevel.INITIAL);

//Next build. Since we trigger manually. The project should pick up the previous baseline.
AbstractBuild<?,?> nothing = jenkins.getProjectBuilder(p).build(new Cause.UserIdCause());
SystemValidator validator2 = new SystemValidator(nothing)
.validateBuiltBaseline(Project.PromotionLevel.BUILT, bl2)
.validateBuild(Result.SUCCESS);
validator2.validate();
}
}
@@ -3,6 +3,7 @@
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.scm.PollingResult;
import hudson.triggers.SCMTrigger;
import java.io.File;
import net.praqma.clearcase.exceptions.ClearCaseException;
import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
@@ -51,7 +52,7 @@ public void testPollingChildsWithChanges() throws Exception {

FreeStyleBuild build = null;
try {
build = project.scheduleBuild2( 0 ).get();
build = project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
fail("The test failed with exception message: "+e.getMessage());
@@ -87,7 +88,7 @@ public void testPollingChildsWithNoChanges() throws Exception {

FreeStyleBuild build = null;
try {
build = project.scheduleBuild2( 0 ).get();
build = project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
fail("The test failed with exception message: "+e.getMessage());
@@ -5,6 +5,7 @@
import hudson.model.Result;
import hudson.model.Slave;
import hudson.scm.PollingResult;
import hudson.triggers.SCMTrigger;
import net.praqma.clearcase.exceptions.ClearCaseException;
import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
import net.praqma.clearcase.test.junit.ClearCaseRule;
@@ -86,7 +87,7 @@ public void testPoll() throws Exception {
/* BUILD 1 */
AbstractBuild<?, ?> build = null;
try {
build = project.scheduleBuild2( 0 ).get();
build = project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}
@@ -111,7 +112,7 @@ public void testPollThree() throws Exception {
/* BUILD 1 */
AbstractBuild<?, ?> build = null;
try {
build = project.scheduleBuild2( 0 ).get();
build = project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}
@@ -138,7 +139,7 @@ public void testPollThree() throws Exception {
/* BUILD 2 */
AbstractBuild<?, ?> build2 = null;
try {
build2 = project.scheduleBuild2( 0 ).get();
build2 = project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}
@@ -2,6 +2,7 @@

import hudson.model.FreeStyleProject;
import hudson.scm.PollingResult;
import hudson.triggers.SCMTrigger;
import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
import net.praqma.clearcase.test.junit.ClearCaseRule;
import net.praqma.hudson.scm.pollingmode.PollSelfMode;
@@ -25,7 +26,7 @@ public void testPollingSelfWithBaselines() throws Exception {

/* BUILD 1 */
try {
project.scheduleBuild2( 0 ).get();
project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}
@@ -40,41 +41,41 @@ public void testPollingSelfWithNoBaselines() throws Exception {

/* BUILD 1 */
try {
project.scheduleBuild2( 0 ).get();
project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}
/* BUILD 2 */
try {
project.scheduleBuild2( 0 ).get();
project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}

/* BUILD 3 */
try {
project.scheduleBuild2( 0 ).get();
project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}

/* BUILD 4 */
try {
project.scheduleBuild2( 0 ).get();
project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}

/* BUILD 5 */
try {
project.scheduleBuild2( 0 ).get();
project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}

/* BUILD 6 */
try {
project.scheduleBuild2( 0 ).get();
project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for testing") ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}
@@ -8,6 +8,7 @@
import hudson.model.AbstractBuild;
import hudson.model.Project;
import hudson.model.Result;
import hudson.triggers.SCMTrigger;
import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Stream;
@@ -141,14 +142,14 @@ public void siblingsUsingUseNewest() throws Exception {
.setMode(mode)
.getProject();

AbstractBuild<?, ?> build = jenkins.getProjectBuilder(project).build();
AbstractBuild<?, ?> build = jenkins.getProjectBuilder(project).build(new SCMTrigger.SCMTriggerCause("Trigger change for SCM test"));
SystemValidator validator = new SystemValidator( build ).
validateBuild( build.getResult() ).
validateBuiltBaseline( PromotionLevel.BUILT, baseline, false ).
validateCreatedBaseline( true );
validator.validate();

AbstractBuild<?, ?> build2 = jenkins.getProjectBuilder(project).build();
AbstractBuild<?, ?> build2 = jenkins.getProjectBuilder(project).build(new SCMTrigger.SCMTriggerCause("Trigger change for SCM test"));
SystemValidator validator2 = new SystemValidator( build2 ).validateBuild(Result.NOT_BUILT);
validator2.validate();
}
@@ -16,6 +16,7 @@
import hudson.model.BuildListener;
import hudson.model.FreeStyleBuild;
import hudson.scm.PollingResult;
import hudson.triggers.SCMTrigger;
import net.praqma.hudson.scm.CCUCMScm;

import net.praqma.clearcase.test.junit.ClearCaseRule;
@@ -54,7 +55,7 @@ public void jenkins14806() throws Exception {
project.getBuildersList().add( new WaitBuilder() );

System.out.println( "Async build" );
Future<FreeStyleBuild> futureBuild = project.scheduleBuild2( 0 );
Future<FreeStyleBuild> futureBuild = project.scheduleBuild2( 0, new SCMTrigger.SCMTriggerCause("Triggered for test") );

/* Remove the builder again */
System.out.println( "Clear builders" );

0 comments on commit 1e72ba2

Please sign in to comment.
You can’t perform that action at this time.