Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Expand All @@ -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());
Expand Down Expand Up @@ -56,19 +61,37 @@
*/
@RequirePOST
@JavaScriptMethod
public boolean doRebuild() throws IOException, ExecutionException {
public JSONObject doRebuild() throws IOException, ExecutionException, Exception {

Check warning

Code scanning / Jenkins Security Scan

Stapler: Missing permission check Warning

Potential missing permission check in AbstractPipelineViewAction#doRebuild
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();
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (rebuildButton) {
const rebuildAction = window[`${rebuildButton.dataset.proxyName}`];
rebuildAction.doRebuild(function (success) {
const result = success.responseJSON;
if (result) {
if (result && result.success) {
window.hoverNotification(rebuildButton.dataset.successMessage, rebuildButton);
}
});
Expand Down