Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #113 from Greybird/master
[JENKINS-40803] provide a config file resolution context for promotions
- Loading branch information
Showing
3 changed files
with
87 additions
and
1 deletion.
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
20 changes: 20 additions & 0 deletions
20
src/main/java/hudson/plugins/promoted_builds/JobPropertyImplConfigContextResolver.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,20 @@ | ||
package hudson.plugins.promoted_builds; | ||
|
||
import hudson.Extension; | ||
import hudson.model.ItemGroup; | ||
import org.jenkinsci.plugins.configfiles.ConfigContextResolver; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
@Extension(optional = true) | ||
@Restricted(NoExternalUse.class) | ||
public class JobPropertyImplConfigContextResolver extends ConfigContextResolver { | ||
|
||
@Override | ||
public ItemGroup getConfigContext(ItemGroup itemGroup) { | ||
if (itemGroup instanceof JobPropertyImpl) { | ||
return JobPropertyImpl.class.cast(itemGroup).getOwner().getParent(); | ||
} | ||
return null; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/hudson/plugins/promoted_builds/PromotionConfigFilesTest.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,55 @@ | ||
package hudson.plugins.promoted_builds; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Result; | ||
import hudson.plugins.promoted_builds.conditions.SelfPromotionCondition; | ||
import org.jenkinsci.plugins.configfiles.GlobalConfigFiles; | ||
import org.jenkinsci.plugins.configfiles.builder.ConfigFileBuildStep; | ||
import org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile; | ||
import org.jenkinsci.plugins.configfiles.custom.CustomConfig; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class PromotionConfigFilesTest { | ||
|
||
private static final String CONFIG_ID = "ConfigFilesTestId"; | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Test | ||
public void testPromotionConfigFilesAreRetrievedFromParentJobContext() throws Exception { | ||
GlobalConfigFiles store = r.getInstance().getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class); | ||
Assert.assertTrue(store.getConfigs().isEmpty()); | ||
|
||
CustomConfig config = new CustomConfig(CONFIG_ID, "name", "comment", "content"); | ||
store.save(config); | ||
|
||
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)); | ||
List<ManagedFile> managedFiles = new ArrayList<>(); | ||
managedFiles.add(new ManagedFile(CONFIG_ID)); | ||
promo1.getBuildSteps().add(new ConfigFileBuildStep(managedFiles)); | ||
|
||
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(); | ||
assertEquals(Result.SUCCESS, pb.getResult()); | ||
} | ||
} |