-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into JENKINS-49486-initial
- Loading branch information
Showing
4 changed files
with
107 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
</parent> | ||
|
||
<artifactId>promoted-builds</artifactId> | ||
<version>3.0</version> | ||
<version>3.2-SNAPSHOT</version> | ||
<packaging>hpi</packaging> | ||
|
||
<name>Jenkins promoted builds plugin</name> | ||
|
@@ -39,7 +39,7 @@ | |
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection> | ||
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection> | ||
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url> | ||
<tag>promoted-builds-3.0</tag> | ||
<tag>HEAD</tag> | ||
</scm> | ||
<licenses> | ||
<license> | ||
|
@@ -97,6 +97,11 @@ | |
<version>1.25</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>structs</artifactId> | ||
<version>1.7</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
|
@@ -112,7 +117,7 @@ | |
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>token-macro</artifactId> | ||
<version>1.12.1</version> | ||
<version>2.0</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
|
@@ -138,6 +143,12 @@ | |
<version>1.4.7-jenkins-1</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>config-file-provider</artifactId> | ||
<version>2.18</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<!-- TODO: it is something insane, no? --> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
|
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()); | ||
} | ||
} |
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