Skip to content

Commit 373dba9

Browse files
authored
Merge pull request #861 from lamaral/bugfix
Fix snippet generator when a custom crumb header is configured
2 parents 745c4a4 + 561e445 commit 373dba9

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/handle-prototype.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function handlePrototype(url, crumb) {
1+
function handlePrototype(url) {
22
buildFormTree(document.forms.config);
33
// TODO JSON.stringify fails in some circumstances: https://gist.github.com/jglick/70ec4b15c1f628fdf2e9 due to Array.prototype.toJSON
44
// TODO simplify when Prototype.js is removed
@@ -7,13 +7,11 @@ function handlePrototype(url, crumb) {
77
return; // just a separator
88
}
99

10-
const headers = new Headers();
11-
headers.append("Content-Type", "application/x-www-form-urlencoded");
12-
headers.append("Jenkins-Crumb", crumb);
13-
1410
fetch(url, {
1511
method: "POST",
16-
headers: headers,
12+
headers: crumb.wrap({
13+
"Content-Type": "application/x-www-form-urlencoded"
14+
}),
1715
body: "json=" + encodeURIComponent(json),
1816

1917
})
@@ -37,9 +35,8 @@ document.addEventListener('DOMContentLoaded', () => {
3735

3836
const generatePipelineScript = document.getElementById("generatePipelineScript");
3937
const url = generatePipelineScript.getAttribute("data-url");
40-
const crumb = generatePipelineScript.getAttribute("data-crumb");
4138
generatePipelineScript.onclick = (_) => {
42-
handlePrototype(url, crumb);
39+
handlePrototype(url);
4340
return false;
4441
};
4542

plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/index.jelly

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ THE SOFTWARE.
7070
<f:block>
7171
<input type="button" id="generatePipelineScript" value="${%Generate Pipeline Script}"
7272
class="submit-button primary"
73-
data-url="${rootURL}/${it.GENERATE_URL}"
74-
data-crumb="${h.getCrumb(request)}"/>
73+
data-url="${rootURL}/${it.GENERATE_URL}"/>
7574
<f:textarea id="prototypeText" readonly="true" style="margin-top: 10px"/>
7675
<l:copyButton text="" clazz="jenkins-hidden jenkins-!-margin-top-1"/>
7776
<st:adjunct includes="org.jenkinsci.plugins.workflow.cps.Snippetizer.handle-prototype"/>

0 commit comments

Comments
 (0)