Skip to content

Commit 9da23b4

Browse files
committed
[JENKINS-73813] Show a notification when scheduling a build fails
When a build is triggered via the UI (either on the job page or via the buildbuttoncolumn in a view) and the crumb is no longer valid, there was still the tooltip shown that the build was scheduled, whereas nothing happened. This change will show a notification when scheduling failed.
1 parent 435bb79 commit 9da23b4

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

core/src/main/resources/hudson/views/BuildButtonColumn/column.jelly

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ THE SOFTWARE.
3737
<j:set var="title" value="${%Schedule_a_task_with_parameters(h.getRelativeDisplayNameFrom(job, itemGroup),it.taskNoun(job))}"/>
3838
</j:when>
3939
<j:otherwise>
40-
<span class="build-button-column-icon-reference-holder" data-id="${id}" data-url="${href}" data-notification="${%Task_scheduled(it.taskNoun(job))}"/>
40+
<span class="build-button-column-icon-reference-holder" data-id="${id}" data-url="${href}"
41+
data-notification="${%Task_scheduled(it.taskNoun(job))}"
42+
data-failure="${%Task_schedule_failed(h.getRelativeDisplayNameFrom(job, itemGroup))}"
43+
/>
4144
<j:set var="title" value="${%Schedule_a_task(h.getRelativeDisplayNameFrom(job, itemGroup),it.taskNoun(job))}"/>
4245
</j:otherwise>
4346
</j:choose>

core/src/main/resources/hudson/views/BuildButtonColumn/column.properties

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
Task_scheduled={0} scheduled
2424
Schedule_a_task=Schedule a {1} for {0}
2525
Schedule_a_task_with_parameters=Schedule a {1} with parameters for {0}
26+
Task_schedule_failed=Failed to schedule build for {0}.

core/src/main/resources/hudson/views/BuildButtonColumn/icon.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ Behaviour.specify(
55
function (e) {
66
var url = e.getAttribute("data-url");
77
var message = e.getAttribute("data-notification");
8+
var failure = e.getAttribute("data-failure");
89
var id = e.getAttribute("data-id");
910
var icon = document.getElementById(id);
1011

1112
icon.onclick = function () {
1213
fetch(url, {
1314
method: "post",
1415
headers: crumb.wrap({}),
15-
});
16-
hoverNotification(message, this, -100);
16+
}).then((rsp) => {
17+
if (rsp.ok) {
18+
hoverNotification(message, this, -100);
19+
} else {
20+
notificationBar.show(failure, notificationBar.ERROR)
21+
}
22+
});;
1723
return false;
1824
};
1925
},

core/src/main/resources/lib/hudson/project/configurable.jelly

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ THE SOFTWARE.
2727
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
2828
<j:if test="${it.buildable}">
2929
<st:adjunct includes="lib.hudson.project.configurable.configurable"/>
30-
<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}"/>
30+
<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}"/>
3131
</j:if>
3232
<j:choose>
3333
<j:when test="${h.hasPermission(it,it.CONFIGURE)}">

core/src/main/resources/lib/hudson/project/configurable.properties

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222

2323
delete=Delete {0}
2424
delete.confirm=Delete the {0} ‘{1}’?
25+
buildFailed=Failed to schedule build. Reload the page and try again.

core/src/main/resources/lib/hudson/project/configurable/configurable.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
function foo(el, ev) {
55
let parameterized = el.dataset.parameterized;
66
let success = el.dataset.buildSuccess;
7+
let failure = el.dataset.buildFailure;
78
if (parameterized === "false") {
89
fetch(el.href, {
910
method: "post",
1011
headers: crumb.wrap({}),
12+
}).then((rsp) => {
13+
if (rsp.ok) {
14+
hoverNotification(success, ev.target.parentNode);
15+
} else {
16+
notificationBar.show(failure, notificationBar.ERROR)
17+
}
1118
});
12-
hoverNotification(success, ev.target.parentNode);
1319
ev.preventDefault();
1420
}
1521
}

0 commit comments

Comments
 (0)