Skip to content

Commit

Permalink
[JENKINS-73813] Show a notification when scheduling a build fails (#9787
Browse files Browse the repository at this point in the history
)

Co-authored-by: Jan Faracik <[email protected]>
Co-authored-by: Tim Jacomb <[email protected]>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent fe80df5 commit 8458d66
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ THE SOFTWARE.
<j:set var="title" value="${%Schedule_a_task_with_parameters(h.getRelativeDisplayNameFrom(job, itemGroup),it.taskNoun(job))}"/>
</j:when>
<j:otherwise>
<span class="build-button-column-icon-reference-holder" data-id="${id}" data-url="${href}" data-notification="${%Task_scheduled(it.taskNoun(job))}"/>
<span class="build-button-column-icon-reference-holder" data-id="${id}" data-url="${href}"
data-notification="${%Task_scheduled(it.taskNoun(job))}"
data-failure="${%Task_schedule_failed(h.getRelativeDisplayNameFrom(job, itemGroup))}"
/>
<j:set var="title" value="${%Schedule_a_task(h.getRelativeDisplayNameFrom(job, itemGroup),it.taskNoun(job))}"/>
</j:otherwise>
</j:choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
Task_scheduled={0} scheduled
Schedule_a_task=Schedule a {1} for {0}
Schedule_a_task_with_parameters=Schedule a {1} with parameters for {0}
Task_schedule_failed=Failed to schedule build for {0}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ Behaviour.specify(
function (e) {
var url = e.getAttribute("data-url");
var message = e.getAttribute("data-notification");
var failure = e.getAttribute("data-failure");
var id = e.getAttribute("data-id");
var icon = document.getElementById(id);

icon.onclick = function () {
fetch(url, {
method: "post",
headers: crumb.wrap({}),
}).then((rsp) => {
if (rsp.ok) {
notificationBar.show(message, notificationBar.SUCCESS);
} else {
notificationBar.show(failure, notificationBar.ERROR);
}
});
hoverNotification(message, this, -100);
return false;
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
<j:if test="${it.buildable}">
<st:adjunct includes="lib.hudson.project.configurable.configurable"/>
<l:task href="${url}/build?delay=0sec" icon="icon-clock icon-md" permission="${it.BUILD}" post="${!it.parameterized}" data-callback="lib_hudson_project_configurable_build_now_callback" data-build-success="${%Build scheduled}" data-parameterized="${it.parameterized}" title="${it.buildNowText}"/>
<l:task href="${url}/build?delay=0sec" icon="icon-clock icon-md" permission="${it.BUILD}" post="${!it.parameterized}" data-callback="lib_hudson_project_configurable_build_now_callback" data-build-failure="${%buildFailed}" data-build-success="${%Build scheduled}" data-parameterized="${it.parameterized}" title="${it.buildNowText}"/>
</j:if>
<j:choose>
<j:when test="${h.hasPermission(it,it.CONFIGURE)}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@

delete=Delete {0}
delete.confirm=Delete the {0} ‘{1}’?
buildFailed=Failed to schedule build. Reload the page and try again.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
function foo(el, ev) {
let parameterized = el.dataset.parameterized;
let success = el.dataset.buildSuccess;
let failure = el.dataset.buildFailure;
if (parameterized === "false") {
fetch(el.href, {
method: "post",
headers: crumb.wrap({}),
}).then((rsp) => {
if (rsp.ok) {
notificationBar.show(success, notificationBar.SUCCESS);
} else {
notificationBar.show(failure, notificationBar.ERROR);
}
});
hoverNotification(success, ev.target.parentNode);
ev.preventDefault();
}
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/lib/layout/task.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ THE SOFTWARE.
href="${href}"
class="task-link task-link-no-confirm ${isCurrent ? 'task-link--active' : ''}"
data-task-success="${%Done.}"
data-task-failure="${%Failed.}"
data-task-post="${attrs.post}"
ATTRIBUTES="${attrs}"
EXCEPT="badge confirmationMessage contextMenu destructive enabled href icon permission permissions post requiresConfirmation title">
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/resources/lib/layout/task/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Behaviour.specify("a.task-link-no-confirm", "task-link", 0, function (el) {
let post = el.dataset.taskPost;
let callback = el.dataset.callback;
let success = el.dataset.taskSuccess;
let failure = el.dataset.taskFailure;
let href = el.href;

if (callback !== undefined) {
Expand All @@ -20,8 +21,13 @@ Behaviour.specify("a.task-link-no-confirm", "task-link", 0, function (el) {
fetch(href, {
method: "post",
headers: crumb.wrap({}),
}).then((rsp) => {
if (rsp.ok) {
notificationBar(success, notificationBar.SUCCESS);
} else {
notificationBar(failure, notificationBar.ERROR);
}
});
hoverNotification(success, el.parentNode);
ev.preventDefault();
};
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/js/components/dropdowns/jumplists.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,19 @@ function mapChildrenItemsToDropdownItems(items) {
fetch(item.url, {
method: "post",
headers: crumb.wrap({}),
}).then((rsp) => {
if (rsp.ok) {
notificationBar.show(
item.displayName + ": Done.",
notificationBar.SUCCESS,
);
} else {
notificationBar.show(
item.displayName + ": Failed.",
notificationBar.ERROR,
);
}
});
notificationBar.show(
item.displayName + ": Done.",
notificationBar.SUCCESS,
);
}
}
},
Expand Down

0 comments on commit 8458d66

Please sign in to comment.