mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-15 13:02:19 +00:00
[FIXES JENKINS-47406] Milestone JOB_LOADED is now attained after cleaning up obsolete items (#3078)
* [FIXES JENKINS-47406] Milestone JOB_LOADED is now attained after cleaning up obsolete items This allows @Initializer(after=InitMilestone.JOB_LOADED) implementations to create items safely without risking them to be removed. * [JENKINS-47406] Add test with an initializer creating a job * Revert "[FIXES JENKINS-47406] Milestone JOB_LOADED is now attained after cleaning up obsolete items" This reverts commit79ce796b00. * [JENKINS-47406] Reinstate the test with Jesse's solution * Reverted this commit by mistake Revert "Revert "[FIXES JENKINS-47406] Milestone JOB_LOADED is now attained after cleaning up obsolete items"" This reverts commit36c499c58c. * Add link to hpi sources * Fix Mix-up after the previous merge
This commit is contained in:
1 parent
53ac66eec0
commit
0311b2dffa
3 files changed
+15
-3
No files matched your search
@@ -3054,8 +3054,9 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
|
||||
}
|
||||
});
|
||||
|
||||
List<Handle> loadJobs = new ArrayList<>();
|
||||
for (final File subdir : subdirs) {
|
||||
g.requires(loadJenkins).attains(JOB_LOADED).notFatal().add("Loading item " + subdir.getName(), new Executable() {
|
||||
loadJobs.add(g.requires(loadJenkins).attains(JOB_LOADED).notFatal().add("Loading item " + subdir.getName(), new Executable() {
|
||||
public void run(Reactor session) throws Exception {
|
||||
if(!Items.getConfigFile(subdir).exists()) {
|
||||
//Does not have job config file, so it is not a jenkins job hence skip it
|
||||
@@ -3065,10 +3066,10 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
|
||||
items.put(item.getName(), item);
|
||||
loadedNames.add(item.getName());
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
g.requires(JOB_LOADED).attains(COMPLETED).add("Cleaning up obsolete items deleted from the disk", new Executable() {
|
||||
g.requires(loadJobs.toArray(new Handle[loadJobs.size()])).attains(JOB_LOADED).add("Cleaning up obsolete items deleted from the disk", new Executable() {
|
||||
public void run(Reactor reactor) throws Exception {
|
||||
// anything we didn't load from disk, throw them away.
|
||||
// doing this after loading from disk allows newly loaded items
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
package jenkins.model;
|
||||
|
||||
import static hudson.init.InitMilestone.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
@@ -44,6 +45,7 @@ import com.gargoylesoftware.htmlunit.WebResponse;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlForm;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
|
||||
import hudson.init.Initializer;
|
||||
import hudson.maven.MavenModuleSet;
|
||||
import hudson.maven.MavenModuleSetBuild;
|
||||
import hudson.model.Computer;
|
||||
@@ -72,6 +74,7 @@ import org.jvnet.hudson.test.ExtractResourceSCM;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
import org.jvnet.hudson.test.JenkinsRule.WebClient;
|
||||
import org.jvnet.hudson.test.TestExtension;
|
||||
import org.jvnet.hudson.test.recipes.WithPlugin;
|
||||
import org.kohsuke.stapler.HttpResponse;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
@@ -83,6 +86,7 @@ import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import org.jvnet.hudson.test.MockAuthorizationStrategy;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
@@ -683,4 +687,11 @@ public class JenkinsTest {
|
||||
VersionNumber nullVersion = Jenkins.getStoredVersion();
|
||||
assertNull(nullVersion);
|
||||
}
|
||||
|
||||
@Issue("JENKINS-47406")
|
||||
@Test
|
||||
@WithPlugin("jenkins-47406.hpi") // Sources: https://github.com/Vlatombe/jenkins-47406
|
||||
public void jobCreatedByInitializerIsRetained() {
|
||||
assertNotNull("JENKINS-47406 should exist", j.jenkins.getItem("JENKINS-47406"));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user