mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
added URL for triggering SCM, but this is still incomplete as this requires SCMTrigger to be configured.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@5838 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
f50b775ddc
commit
dd7563a883
2 files changed
+46
-18
No files matched your search
@@ -21,6 +21,7 @@ import hudson.tasks.BuildTrigger;
|
||||
import hudson.triggers.Trigger;
|
||||
import hudson.triggers.TriggerDescriptor;
|
||||
import hudson.triggers.Triggers;
|
||||
import hudson.triggers.SCMTrigger;
|
||||
import hudson.util.EditDistance;
|
||||
|
||||
import java.io.File;
|
||||
@@ -331,6 +332,17 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
|
||||
return Hudson.getInstance().getQueue().add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a polling of this project.
|
||||
*/
|
||||
public boolean schedulePolling() {
|
||||
if(isDisabled()) return false;
|
||||
SCMTrigger scmt = getTrigger(SCMTrigger.class);
|
||||
if(scmt==null) return false;
|
||||
scmt.run();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the build is in the queue.
|
||||
*/
|
||||
@@ -630,6 +642,17 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
|
||||
return (Map)Descriptor.toMap(triggers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the specific trigger, or null if the propert is not configured for this job.
|
||||
*/
|
||||
public <T extends Trigger> T getTrigger(Class<T> clazz) {
|
||||
for (Trigger p : triggers) {
|
||||
if(clazz.isInstance(p))
|
||||
return clazz.cast(p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// fingerprint related
|
||||
@@ -737,7 +760,20 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
|
||||
* Schedules a new build command.
|
||||
*/
|
||||
public void doBuild( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
|
||||
BuildAuthorizationToken.startBuildIfAuthorized(authToken,this,req,rsp);
|
||||
if(BuildAuthorizationToken.canStartBuild(authToken, req, rsp)) {
|
||||
scheduleBuild();
|
||||
rsp.forwardToPreviousPage(req);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a new SCM polling command.
|
||||
*/
|
||||
public void doPolling( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
|
||||
if(BuildAuthorizationToken.canStartBuild(authToken, req, rsp)) {
|
||||
schedulePolling();
|
||||
rsp.forwardToPreviousPage(req);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@ import hudson.Util;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -28,26 +27,19 @@ public final class BuildAuthorizationToken {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void startBuildIfAuthorized(BuildAuthorizationToken token, BuildableItem job, StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
|
||||
if(!Hudson.getInstance().isUseSecurity() || (token!=null && token.authorizedToStartBuild(req,rsp)) || Hudson.adminCheck(req, rsp)) {
|
||||
job.scheduleBuild();
|
||||
rsp.forwardToPreviousPage(req);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean authorizedToStartBuild(StaplerRequest req, StaplerResponse rsp) throws IOException {
|
||||
public static boolean canStartBuild(BuildAuthorizationToken token, StaplerRequest req, StaplerResponse rsp) throws IOException {
|
||||
if (!Hudson.getInstance().isUseSecurity())
|
||||
// everyone is authorized
|
||||
return true;
|
||||
return true; // everyone is authorized
|
||||
|
||||
if(token != null) {
|
||||
//check the provided token
|
||||
String providedToken = req.getParameter("token");
|
||||
if (providedToken != null && providedToken.equals(token))
|
||||
return true;
|
||||
if(token!=null) {
|
||||
if(token.token != null) {
|
||||
//check the provided token
|
||||
String providedToken = req.getParameter("token");
|
||||
if (providedToken != null && providedToken.equals(token.token))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise it must be an admin
|
||||
return Hudson.adminCheck(req, rsp);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user