From b0a1d39f3ae46352e8284fed6fabf743f57d36c4 Mon Sep 17 00:00:00 2001 From: Matt Kucia Date: Thu, 26 Nov 2020 23:08:47 +0800 Subject: [PATCH] config: Add global option to disable pipeline replays. Replay does confuse users when used in dynamic worker configuration. For such, allow to disable feature. Users will still be able to schedule new builds or use rebuild plugin. --- .../plugins/workflow/cps/WorkflowConfig.java | 60 +++++++++++++++++++ .../workflow/cps/replay/ReplayAction.java | 9 +++ .../workflow/cps/WorkflowConfig/config.jelly | 9 +++ .../cps/WorkflowConfig/config.properties | 1 + 4 files changed, 79 insertions(+) create mode 100644 src/main/java/org/jenkinsci/plugins/workflow/cps/WorkflowConfig.java create mode 100644 src/main/resources/org/jenkinsci/plugins/workflow/cps/WorkflowConfig/config.jelly create mode 100644 src/main/resources/org/jenkinsci/plugins/workflow/cps/WorkflowConfig/config.properties diff --git a/src/main/java/org/jenkinsci/plugins/workflow/cps/WorkflowConfig.java b/src/main/java/org/jenkinsci/plugins/workflow/cps/WorkflowConfig.java new file mode 100644 index 000000000..55be55bf5 --- /dev/null +++ b/src/main/java/org/jenkinsci/plugins/workflow/cps/WorkflowConfig.java @@ -0,0 +1,60 @@ +/* + * The MIT License + * + * Copyright 2020 Motional + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.jenkinsci.plugins.workflow.cps; + +import hudson.Extension; +import jenkins.model.GlobalConfiguration; +import net.sf.json.JSONObject; +import org.kohsuke.stapler.DataBoundSetter; +import org.kohsuke.stapler.StaplerRequest; + +@Extension +public class WorkflowConfig extends GlobalConfiguration { + private boolean replayDisabled = false; + + + public WorkflowConfig() { + load(); + } + + public static WorkflowConfig getInstance() { + return GlobalConfiguration.all().get(WorkflowConfig.class); + } + + @Override + public boolean configure(StaplerRequest req, JSONObject o) throws FormException { + this.replayDisabled = o.getBoolean("replayDisabled"); + save(); + return super.configure(req, o); + } + + public boolean getReplayDisabled() { + return this.replayDisabled; + } + @DataBoundSetter + public void setReplayDisabled(boolean replayDisabled) { + this.replayDisabled = replayDisabled; + } +} diff --git a/src/main/java/org/jenkinsci/plugins/workflow/cps/replay/ReplayAction.java b/src/main/java/org/jenkinsci/plugins/workflow/cps/replay/ReplayAction.java index a46920749..c6903b4df 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/cps/replay/ReplayAction.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/cps/replay/ReplayAction.java @@ -69,6 +69,7 @@ import org.acegisecurity.AccessDeniedException; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution; +import org.jenkinsci.plugins.workflow.cps.WorkflowConfig; import org.jenkinsci.plugins.workflow.flow.FlowExecution; import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner; import org.kohsuke.accmod.Restricted; @@ -140,6 +141,10 @@ private ReplayAction(Run run) { return false; } + if (WorkflowConfig.getInstance().getReplayDisabled() == true) { + return false; + } + return true; } @@ -152,6 +157,10 @@ private ReplayAction(Run run) { return false; } + if (WorkflowConfig.getInstance().getReplayDisabled() == true) { + return false; + } + CpsFlowExecution exec = getExecutionLazy(); if (exec != null) { return exec.isSandbox() || Jenkins.get().hasPermission(Jenkins.RUN_SCRIPTS); // We have to check for ADMIN because un-sandboxed code can execute arbitrary on-master code diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/cps/WorkflowConfig/config.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/cps/WorkflowConfig/config.jelly new file mode 100644 index 000000000..4292de39a --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/workflow/cps/WorkflowConfig/config.jelly @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/cps/WorkflowConfig/config.properties b/src/main/resources/org/jenkinsci/plugins/workflow/cps/WorkflowConfig/config.properties new file mode 100644 index 000000000..d4d67b675 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/workflow/cps/WorkflowConfig/config.properties @@ -0,0 +1 @@ +title.configtitle=Pipeline Workflows