Skip to content

Commit

Permalink
Fix job build with form data (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
silas authored Jun 6, 2023
1 parent 034f18b commit b1118eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion lib/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Job {

if (form) {
for (const [name, value] of Object.entries(data)) {
form.append(key, value);
form.append(name, value);
}
req.body = form;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jenkins",
"description": "Jenkins client",
"version": "1.0.1",
"version": "1.0.2",
"main": "./lib",
"files": [
"./lib"
Expand Down
21 changes: 21 additions & 0 deletions test/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,27 @@ describe("jenkins", function () {
await this.jenkins.job.build("test", opts);
});

nit("should work with form data parameters", async function () {
this.jenkins = new Jenkins({
baseUrl: this.url,
crumbIssuer: helper.config.crumbIssuer,
formData: require("form-data"),
});
this.jenkins.on("log", debug("jenkins:client"));

this.nock
.post("/job/test/buildWithParameters", /filename="oneName"/gm)
.reply(201);

const opts = {
parameters: {
oneName: Buffer.from("oneValue"),
twoName: "twoValue",
},
};
await this.jenkins.job.build("test", opts);
});

nit("should work with a token and parameters", async function () {
this.nock
.post("/job/test/buildWithParameters?token=secret", {
Expand Down

0 comments on commit b1118eb

Please sign in to comment.