I am trying to make a function on my website to stop a running Jenkins pipeline.
I tried below,
let myHeaders = new Headers({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
})
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic c3RhcnNpdDpjaXNjbzEyMw==");
let requestOptions = {
method: 'POST',
headers: myHeaders,
redirect: 'follow'
mode: 'cors',
};
fetch("<my_server>/<buildNum>/stop", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
This gives me an error
Access to fetch at '<my_server>/<buildNum>/stop' from origin
'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass
access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
If an opaque response serves your needs, set the request's mode to 'no-cors'
to fetch the resource with CORS disabled.
I added the option Access-Control-Allow-Origin
to the header and also set the mode
to cors
in the requestOptions
.
Any help, please?