-
Notifications
You must be signed in to change notification settings - Fork 63
RFC: Add a way to get last queue number and pass the relative url #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
package io.jenkins.plugins.pipelinegraphview.utils; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import hudson.model.Action; | ||
import hudson.model.BallColor; | ||
import hudson.model.Item; | ||
import hudson.model.Queue; | ||
import hudson.security.Permission; | ||
import hudson.util.HttpResponses; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import net.sf.json.JSONObject; | ||
|
||
import org.jenkins.ui.icon.IconSpec; | ||
import org.jenkinsci.plugins.workflow.cps.replay.ReplayAction; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
|
@@ -23,6 +15,19 @@ | |
import org.kohsuke.stapler.bind.JavaScriptMethod; | ||
import org.kohsuke.stapler.interceptor.RequirePOST; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import hudson.model.Action; | ||
import hudson.model.BallColor; | ||
import hudson.model.Item; | ||
import hudson.model.Queue; | ||
import hudson.model.Run; | ||
import hudson.model.queue.QueueTaskFuture; | ||
import hudson.security.Permission; | ||
import hudson.util.HttpResponses; | ||
import net.sf.json.JSONObject; | ||
|
||
public abstract class AbstractPipelineViewAction implements Action, IconSpec { | ||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
private static final Logger LOGGER = Logger.getLogger(AbstractPipelineViewAction.class.getName()); | ||
|
@@ -56,19 +61,37 @@ | |
*/ | ||
@RequirePOST | ||
@JavaScriptMethod | ||
public boolean doRebuild() throws IOException, ExecutionException { | ||
public JSONObject doRebuild() throws IOException, ExecutionException, Exception { | ||
JSONObject result = new JSONObject(); | ||
result.put("success",false); | ||
result.put("url",""); | ||
|
||
if (run != null) { | ||
run.checkAnyPermission(Item.BUILD); | ||
ReplayAction replayAction = run.getAction(ReplayAction.class); | ||
Queue.Item item = | ||
replayAction.run2(replayAction.getOriginalScript(), replayAction.getOriginalLoadedScripts()); | ||
|
||
if (item == null) { | ||
return false; | ||
return result; | ||
} | ||
return true; | ||
|
||
QueueTaskFuture<? extends Run<?, ?>> f = (QueueTaskFuture) item.getFuture(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you have a look at how blue ocean does it please? I don't think we want a thread waiting for start. A better way is probably to poll in the frontend for a bit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timja Yes I will do it |
||
if (f == null) { | ||
return result; | ||
} | ||
Run<?, ?> b = f.waitForStart(); | ||
|
||
Integer number = b.getNumber(); | ||
|
||
result.put("success", true); | ||
result.put("url", run.getUrl().replace("/" + run.getNumber() + "/", "/" + number + "/") | ||
+ "pipeline-graph/"); | ||
|
||
return result; | ||
} | ||
return false; | ||
|
||
return result; | ||
} | ||
|
||
public String getFullBuildDisplayName() { | ||
|
Check warning
Code scanning / Jenkins Security Scan
Stapler: Missing permission check Warning