Skip to content

Commit

Permalink
Clean-up rebuild code to include even non parameterized job
Browse files Browse the repository at this point in the history
We don't need to distinguish between parameterized and non
parameterized job

We can drop some variables

Suggested-by: Tim Jacomb <timjacomb1@gmail.com>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
  • Loading branch information
panicking committed Feb 3, 2025
1 parent 0d8e8f5 commit 69860fa
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import hudson.model.Action;
import hudson.model.BallColor;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Item;
import hudson.model.Queue;
import hudson.security.Permission;
Expand Down Expand Up @@ -53,16 +51,6 @@ public String getBuildDisplayName() {
return run.getDisplayName();
}

public boolean isParameterized() {
ParametersAction paramAction = run.getAction(ParametersAction.class);
if (paramAction != null && !paramAction.getAllParameters().isEmpty()) {
return true;
}

ParametersDefinitionProperty property = run.getParent().getProperty(ParametersDefinitionProperty.class);
return property != null && !property.getParameterDefinitions().isEmpty();
}

/**
* Handles the rebuild request using ReplayAction feature
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<l:hasPermission permission="${it.permission}">
<j:set var="proxyId" value="${h.generateId()}" />
<st:bind value="${it}" var="rebuildAction${proxyId}"/>
<button id="pgv-rebuild" data-success-message="${%Build scheduled}" data-build-path="../../build"
data-parameterized="${it.parameterized}" data-proxy-name="rebuildAction${proxyId}"
<button id="pgv-rebuild" data-success-message="${%Build scheduled}"
data-proxy-name="rebuildAction${proxyId}"
class="jenkins-button jenkins-!-build-color">
<l:icon src="symbol-play-outline plugin-ionicons-api"/>
${%Rebuild}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<j:set var="proxyId" value="${h.generateId()}" />
<st:bind value="${it}" var="rebuildAction${proxyId}"/>
<button id="pgv-rebuild" data-success-message="${%Build scheduled}"
data-build-path="../../build" data-parameterized="${it.parameterized}"
data-proxy-name="rebuildAction${proxyId}"
class="jenkins-button jenkins-!-build-color">
<l:icon src="symbol-play-outline plugin-ionicons-api"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<l:hasPermission permission="${it.permission}">
<j:set var="proxyId" value="${h.generateId()}" />
<st:bind value="${it}" var="rebuildAction${proxyId}"/>
<button id="pgv-rebuild" data-success-message="${%Build scheduled}" data-build-path="../build"
data-parameterized="${it.parameterized}" data-proxy-name="rebuildAction${proxyId}"
<button id="pgv-rebuild" data-success-message="${%Build scheduled}"
data-proxy-name="rebuildAction${proxyId}"
class="jenkins-button jenkins-!-build-color">
<l:icon src="symbol-play-outline plugin-ionicons-api"/>
${%Build}
Expand Down
29 changes: 7 additions & 22 deletions src/main/webapp/js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,12 @@ const rebuildButton = document.getElementById('pgv-rebuild');
if (rebuildButton) {
rebuildButton.addEventListener('click', event => {
event.preventDefault();
const buildUrl = `${rebuildButton.dataset.buildPath}?delay=0sec`
if (rebuildButton.dataset.parameterized === 'true') {
const rebuildAction = window[`${rebuildButton.dataset.proxyName}`];
rebuildAction.doRebuild(function (success) {
const result = success.responseJSON;
if (result) {
window.hoverNotification(rebuildButton.dataset.successMessage, rebuildButton);
}
});
} else {
fetch(buildUrl, {
method: 'post',
headers: crumb.wrap({})
})
.then(res => {
if (!res.ok) {
console.error('Build failed', res);
} else {
window.hoverNotification(rebuildButton.dataset.successMessage, rebuildButton);
}
})
}
const rebuildAction = window[`${rebuildButton.dataset.proxyName}`];
rebuildAction.doRebuild(function (success) {
const result = success.responseJSON;
if (result) {
window.hoverNotification(rebuildButton.dataset.successMessage, rebuildButton);
}
});
})
}

0 comments on commit 69860fa

Please sign in to comment.