Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-22068] Fail promotion builds instead of hanging when a promo…
…tion is built/rebuilt directly (#107) * Prevent RebuildAction from being added to future promotions * Remove deserialized RebuildActions from Promotions * Make promotion builds fail instead of hang when there is no target, and keep promotions from being rebuilt directly * Keep related code grouped together * Add test for PromotionRebuildValidator * Add logging to post2 and move null check to start of method * Add test asserting that rebuilding a promotion directly throws a 404
- Loading branch information
1 parent
14cc62d
commit 043d1a5
Showing
5 changed files
with
196 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/hudson/plugins/promoted_builds/PromotionRebuildValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2017 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.plugins.promoted_builds; | ||
|
||
import com.sonyericsson.rebuild.RebuildValidator; | ||
import hudson.Extension; | ||
import hudson.model.Run; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
/** | ||
* Disables the rebuild button for {@link Promotion} objects since rebuilding | ||
* is handled separately for them. | ||
* | ||
* @see Status | ||
*/ | ||
@Extension | ||
@Restricted(NoExternalUse.class) | ||
public class PromotionRebuildValidator extends RebuildValidator { | ||
|
||
@Override | ||
public boolean isApplicable(Run build) { | ||
return build instanceof Promotion; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/hudson/plugins/promoted_builds/PromotionRebuildValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2017 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.plugins.promoted_builds; | ||
|
||
import com.sonyericsson.rebuild.RebuildAction; | ||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.plugins.promoted_builds.conditions.SelfPromotionCondition; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
import org.junit.Rule; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class PromotionRebuildValidatorTest { | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Test | ||
public void testPromotionsDoNotHaveRebuildActions() throws Exception { | ||
FreeStyleProject p = r.createFreeStyleProject(); | ||
|
||
// promote if the downstream passes | ||
JobPropertyImpl promotion = new JobPropertyImpl(p); | ||
p.addProperty(promotion); | ||
|
||
PromotionProcess promo1 = promotion.addProcess("promo1"); | ||
promo1.conditions.add(new SelfPromotionCondition(false)); | ||
|
||
FreeStyleBuild b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
// internally, the promotion is still an asynchronous process. It just happens | ||
// right away after the build is complete. | ||
Thread.sleep(1000); | ||
|
||
Promotion pb = promo1.getBuilds().iterator().next(); | ||
assertSame(pb.getTarget(), b); | ||
|
||
assertNull(pb.getAction(RebuildAction.class)); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/hudson/plugins/promoted_builds/PromotionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2017 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.plugins.promoted_builds; | ||
|
||
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; | ||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.plugins.promoted_builds.conditions.SelfPromotionCondition; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
import org.junit.Rule; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class PromotionTest { | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Test | ||
public void testRebuildPromotionThrowsException() throws Exception { | ||
FreeStyleProject p = r.createFreeStyleProject("proj1"); | ||
|
||
JobPropertyImpl promotion = new JobPropertyImpl(p); | ||
p.addProperty(promotion); | ||
|
||
PromotionProcess promo1 = promotion.addProcess("promo1"); | ||
promo1.conditions.add(new SelfPromotionCondition(false)); | ||
|
||
FreeStyleBuild b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
// internally, the promotion is still an asynchronous process. It just happens | ||
// right away after the build is complete. | ||
Thread.sleep(1000); | ||
|
||
Promotion pb = promo1.getBuilds().getLastBuild(); | ||
assertSame(pb.getTarget(), b); | ||
|
||
try { | ||
r.createWebClient().goTo("job/"+p.getName()+"/1/promotion/"+promo1.getName()+"/promotionBuild/"+pb.getNumber()+"/rebuild"); | ||
fail("rebuilding a promotion directly should fail"); | ||
} catch (FailingHttpStatusCodeException x) { | ||
assertEquals("wrong status code", 404, x.getStatusCode()); | ||
assertNotEquals("unexpected content", -1, x.getResponse().getContentAsString().indexOf("Promotions may not be rebuilt directly")); | ||
} | ||
} | ||
|
||
} |