Frontend
If you want to make a call from the frontend application the code would look like following:
async function makeRequest() {
const url = "http://YOUR_JENKINS_USER_ID:YOUR_API_TOKEN@YOUR_JENKINS_URL/job/YOUR_JENKINS_JOB/build?token=TokenName"
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
}
});
const resJson = await res.json();
return resJson;
}
Node.js Application
If you want to make request from Node.js
application first you have to install node-fetch
using following command:
npm install node-fetch
Then your code would look like following:
const fetch = require('node-fetch');
async function makeRequest() {
const url = "http://YOUR_JENKINS_USER_ID:YOUR_API_TOKEN@YOUR_JENKINS_URL/job/YOUR_JENKINS_JOB/build?token=TokenName"
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
}
});
const resJson = await res.json();
return resJson;
}