提交 ce7e6390 编写于 作者: K Kohsuke Kawaguchi

Adding the reload job functionality

上级 c0ed4b82
......@@ -58,6 +58,8 @@ Upcoming changes</a>
<li class=rfe>
Access through API token and SSH key login now fully retains group memberships.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20064">issue 20064</a>)
<li class=rfe>
Job can be reloaded individually from disk with "job/FOO/reload" URL or "reload-job" CLI command
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -586,6 +586,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
}
// try to reflect the changes by reloading
doReload();
new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshal(this);
Items.whileUpdatingByXml(new Callable<Void,IOException>() {
@Override public Void call() throws IOException {
......@@ -603,6 +604,34 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
}
}
/**
* Reloads this job from the disk.
*
* Exposed through CLI as well.
*
* TODO: think about exposing this to UI
*
* @since 1.556
*/
@CLIMethod(name="reload-job")
@RequirePOST
public void doReload() throws IOException {
checkPermission(CONFIGURE);
// try to reflect the changes by reloading
getConfigFile().unmarshal(this);
Items.whileUpdatingByXml(new Callable<Void, IOException>() {
@Override
public Void call() throws IOException {
onLoad(getParent(), getRootDir().getName());
return null;
}
});
Jenkins.getInstance().rebuildDependencyGraphAsync();
SaveableListener.fireOnChange(this, getConfigFile());
}
/* (non-Javadoc)
* @see hudson.model.AbstractModelObject#getSearchName()
......
......@@ -91,6 +91,7 @@ BallColor.Unstable=Unstable
CLI.clear-queue.shortDescription=Clears the build queue.
CLI.delete-job.shortDescription=Deletes a job.
CLI.reload-job.shortDescription=Reloads this job from disk.
CLI.disable-job.shortDescription=Disables a job.
CLI.enable-job.shortDescription=Enables a job.
CLI.delete-node.shortDescription=Deletes a node.
......
package hudson.model
import org.junit.Rule
import org.junit.Test
import org.jvnet.hudson.test.JenkinsRule
/**
*
*
* @author Kohsuke Kawaguchi
*/
class AbstractItemTest {
@Rule
public JenkinsRule j = new JenkinsRule()
/**
* Tests the reload functionality
*/
@Test
void reload() {
def jenkins = j.jenkins;
def p = jenkins.createProject(FreeStyleProject.class,"foo");
p.description = "Hello World";
def b = j.assertBuildStatusSuccess(p.scheduleBuild2(0))
b.description = "This is my build"
// update on disk representation
def f = p.configFile.file
f.text = f.text.replaceAll("Hello World","Good Evening");
// reload away
p.doReload()
assert p.description == "Good Evening";
def b2 = p.getBuildByNumber(1)
assert !b.is(b2); // should be different object
assert b.description == b2.description // but should have the same properties
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册