jansepar / node-jenkins-api Goto Github PK
View Code? Open in Web Editor NEWJenkins API for NodeJS
License: MIT License
Jenkins API for NodeJS
License: MIT License
Hi team,
Using the following sniper to create new folders. It fails with 400 response.
jenkins.create_folder(folderName, function(err, data) {
if (err) {
console.log(err)
throw err;
} else {
console.log(" [+] created folder: " + folderName);
}
});
Response:
No Content-Type header set
Page generated: Feb 2, 2019 7:06:01 AM UTCREST APIJenkins ver. 2.162
1
You have not configured the CSRF issuer. This could be a security issue. For more information, please refer to this page.
You can change the current configuration using the Security section CSRF Protection.
Not sure if this is my jenkins setup but curl
execution from #55 works well
curl -XPOST 'http://jenkins/createItem?name=FolderName&mode=com.cloudbees.hudson.plugins.folder.Folder&from=&json=%7B%22name%22%3A%22FolderName%22%2C%22mode%22%3A%22com.cloudbees.hudson.plugins.folder.Folder%22%2C%22from%22%3A%22%22%2C%22Submit%22%3A%22OK%22%7D&Submit=OK' --user user.name:YourAPIToken -H "Content-Type:application/x-www-form-urlencoded"
https://gist.github.com/stuart-warren/7786892
It feels that we need to add headers
while making doRequest
calls. The following fix works well, creates folders.
create_folder: function (folderName, customParams, callback) {
[folderName, customParams, callback] = doArgs(arguments, ['string', ['object', {}], 'function']);
const mode = 'com.cloudbees.hudson.plugins.folder.Folder';
customParams.name = folderName;
customParams.mode = mode;
customParams.Submit = 'OK';
doRequest({
method: 'POST',
urlPattern: [NEWFOLDER],
// added missing headers
// also noparse, response is XML
request: {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
},
noparse: true
}, customParams, callback);
}
That said, a few quetions regarding create_folder
methods:
jenkins.get_config_xml()
returning non-404 is ok?It would be really awesome if this were a NPM package.
at TLSSocket._finishInit (_tls_wrap.js:633:8) code: 'SELF_SIGNED_CERT_IN_CHAIN' }
I am trying to get a running build detail but every call gives a previous completed build details please help me out in this problem thank you
I have a jenkins build for whose login we use github authentication.
How would I specify the API token to init Jenkins?
Tried this against jenkins 2.7.1 which by default is configured securely with "Prevent Cross Site Request Forgery exploits" enabled (e.g. the create_job api). This blows up with a 403 unauthorized error because the API client is not aware of the token and is not submitting it.
See https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API#RemoteaccessAPI-CSRFProtection
Compatibility with older versions of Node is broken. I'm running a ARMv6 Raspberry Pi based build monitor which is restricted to Node 4.7.1 and as of the 'complete refactoring' commit d654756 is broken with the following error:
.../dist/node_modules/jenkins-api/lib/main.js:71
[body, property, callback] = doArgs(arguments, ['string', 'string|array|function', 'function']);
^
ReferenceError: Invalid left-hand side in assignment
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
This hits as soon as var jenkinsapi = require("jenkins-api"); is called.
We are using the Jenkins API to triggered the Jenkins job in Jenkins and get the Jenkins job information .we are using Jenkinsapi packages for achieving that in node.js. Sometimes we are facing below error? Could you please suggest the better solution to resolve that?
Note: We are triggering too more Jenkins job at the same time
Hello,
I'm creating a web app (based on React), this one will display informations about a Jenkins System. Like react is based on NodeJS server i used the node-jenkins-api. I want to get all jobs but i got this error : "Failed to fetch", anyone know why i got this ?
(I had already disable CSRF Protection)
jenkins.delete_build('job-in-jenkins', 'build-number', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
Error:
TypeError: jenkins.delete_build is not a function
I came across this issue yesterday where we had to update the password of the user that we use to trigger the jenkins job. The new randomly generated password had a "/" in it and it completely broke everything. It appeared as though the "/" was confusing the request library and making it cut off at the slash and so the error I was getting was listing the user as the hostname and saying address not found. A co-worker suggested the use of the Node URI library which splits out the username and password and does encoding on them for you: https://nodejs.org/api/url.html#url_url_password.
When I trigger the same job twice, I am getting the same queueId in the location header. Where could be the issue?
How do you resolve unable_to_verify_leaf_signature error? Is there a way to set cert through jenkinsapi.init?
Hi,
When I run git clone [email protected]:jansepar/node-jenkins-api.git
I get:
Cloning into node-jenkins-api...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Can you please investigate and let me know.
getting below error while using copy job API jenkins server is configured with HTTPS
SELF_SIGNED_CERT_IN_CHAIN.
Same things is working fine in other jenkins server which are in HTTP.
Can you please suggest,what is the issue with https?
After applying browserify I'm getting:
XMLHttpRequest cannot load http://jenkins.my.com/job/redis-build/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'chrome-extension://ielhfkekbejhgmdbmnhkbgbdpijempin' is therefore not allowed access.
How can i fix this?
jenkins.console_output('iosBuild', '#415', { depth: 1 }, function (err, data) {
if (err) { return console.log(err); }
console.log(data)
});
when i write this way, data.body is a jenkins html
is this right ?
i think data.body should be the log of the build,like this "started by user ...."
const JenkinsUrl= new URL("http://uname@ip:8080")
JenkinsUrl.password="*******";
console.log(JenkinsUrl.href);
var jenkins=jenkinsapi.init(JenkinsUrl.href);
jenkins.build('test1', {token: '1234'}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.all_builds(job, 'id,timestamp,result,actions', {depth: 1}, function(err, data) {
if (err){
throw err;
}
});
add the 'actions' param, but just return an Incomplete data in actions array, every item only has '_class' property and no 'parameters' property
In my jenkins installation at work because have many products we have regrouped jobs with folders plugin to make sure we do not end up with a huge mess. When calling the jenkins api for the list of all jobs on the server all we get is the list of folders not the job that are contained in them. is there a way around that?
I tried to get last complete build info but return null:
jenkins.last_completed_build_info('Fossil/job/Android_Fossil_3_0_Staging',
function(err,data){
if(data) return console.log(err)
console.log(data)
}
)
==> null
Is it possible to get current running build status and can it be return in a callback function with details? If a build is running in the jenkins server, it needs to be return a callback function once it will be completed.
jenkins.last_build_info only get last build details not current running build details.
When getting the job info while using this function:
jenkins.job_info('job-in-jenkins', function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
Is it possible to get the date on every build, lets say last successful build, last build and so on?
Cheers.
Would you add API to manage nodes (build machines) ?
when response.statusCode !== 200 you always return boolean true
as the error. I'd change that to body
instead, I assume it will contain the actual error message.
I occasionally get an exception which appears to be caused by the JSON.parse logic in each get request. I don't know the exact situation on which it occurs, but the test for error or a statusCode of 200 isn't covering the problem I get. Sometimes the error states
Unexpected token <
Other times the error states
Unexpected end of input
For now I've just put a try catch around
In my scenario I'm polling Jenkins every minute and the error generally happens overnight.
I could capture some further information if you would like.
Hi,
I'm using last_result
and have found that the generated URL is screwed up.
It works if I change the following code:
request({method: 'GET', url: build_url(last_result_url + API, jobname)}, function(error, response, body) {
to the following:
request({method: 'GET', url: last_result_url + API + jobname}, function(error, response, body) {
The reason why is because the call to build_url
fails when it util.format, as there is no %s
in the string, the host is copied into the string a second time. It seems that the last_result_url
already has the host information in it.
In my case the host is different to the value returned in the last_result. Both work, just appears to be a config problem with our jenkins due to network migrations.
I would do a pull request, but I'm not 100% clear on your logic for using build_url
.
When copy a job from a folder and create a new job with in the same folder is not working. It throws 400 status.
jenkins.copy_job('folder/job/jobName', 'folder/newJob', function (config) {
return config.replace(/jobName/g, 'newJob');
}, function (err, data) {
console.log(err);
});
It gets the config.xml from the source job, but the new job url is not generated correctly.
Expected createItem url
http://jenkins/job/FolderName/createItem?name=yourJobName
Actual createItem url
http://jenkins/createItem?name=FolderName/yourJobName
I see that there is an API for copying a job, but I don't see any API for updating the config on an existing job. Is this possible with the current API (like could you copy a job to itself)?
Hi
I'm trying to use this code to start a job in Jenkins
var jenkins = require('jenkins')({ baseUrl: 'MyBaseURL', crumbIssuer: false });
The code is hosted on AWS S3 and the CORS config is this
let jenkins = require('jenkins')({ baseUrl: baseUrl, crumbIssuer: false });
And we have the Jenkins plugin configured like this
Access-Control-Allow-Origins: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Headers: *
Access-Control-Allow-Headers: *
Access-Control-Expose-Headers: 999
This seems to work when we access the s3 website via the internet but we get this message when we go via a proxy within our corporate network
"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."
Any advice on how to debug/resolve this please?
Many thanks for the awesome API! it's helping us a lot.
I was looking to use this library for various interactions with Multibranch Pipeline Jobs in Jenkins. After some initial investigation I haven't been able to get this working. Is this a supported capability, for example, can I trigger a build of a specific branch?
Happy to create a PR for this if its not currently supported.
i am getting this error:
TypeError: jenkins.all_builds is not a function
so i decided to print the jenkins object like this
var jenkinsapi = require('jenkins-api');
var jenkins = jenkinsapi.init('https://${username}:${token}@my-jenkins-uri');
console.log(jenkins)
and from the follow output it seems that some functions are missing for some reason...
{ build: [Function: build],
stop_build: [Function: stop_build],
all_jobs: [Function: all_jobs],
all_jobs_in_view: [Function: all_jobs_in_view],
job_info: [Function: job_info],
last_build_info: [Function: last_build_info],
last_completed_build_info: [Function: last_completed_build_info],
build_info: [Function: build_info],
last_build_report: [Function: last_build_report],
get_config_xml: [Function: get_config_xml],
create_job: [Function: create_job],
update_job: [Function: update_job],
copy_job: [Function: copy_job],
delete_job: [Function: delete_job],
disable_job: [Function: disable_job],
enable_job: [Function: enable_job],
last_success: [Function: last_success],
last_result: [Function: last_result],
queue: [Function: queue],
computers: [Function: computers],
job_output: [Function: job_output] }
I am using node v6.11.1.
Any ideas?
Currently jenkins.build
returns this kind of message.
{ message: 'job is executed',
location: 'http://jenkins.com/queue/item/3435/' }
Would be useful if the build number is returned too as a separate property in the response. This can be used to get the build info and to create the url of the build to allow users use that information. In some versions of jenkins or configurations the queue
url is not available or accessible.
I can get all job by the following ,but i can't build i got 'Server returned unexpected status code: 403'
jenkins.all_jobs({token: jenkins_token,}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.build('xxx',function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
the code is below
jenkins.all_builds('xxxx', 'id,timestamp,result,actions[*]', function(err, data) {
if (err){
console.log('err1', err);
}
console.log('data',data)
});
it runs error and returns ‘Server returned unexpected status code: 400’
but when I use last build it works successfully
jenkins.last_build_info('xxxx', function(err, data) {
if (err){ return console.log('err1', err); }
console.log(data)
});
who can tell me how to solve or the reason is about jenkins set not my code's problem
I am trying to connect to a Jenkins instance that uses a self-signed certificate. I like to be able to pass
rejectUnauthorized : false
to the underlying request
instance.
It would useful to allow the methods from this module to forward options to request
.
I don't see any documentation around support for CRUMB. How to make it work for Jenkins that has CSRF protection configured
In 'request' component, we have rejectUnauthorized: false to avoid such issue, however in this jenkins-api, where can I set this?
I tried to add as request params as well, still same issue.
e.g.: jenkins3.all_builds('my job', {rejectUnauthorized: false},function(err, data)
Also tried to set default configuration when init jenkins API, like:
jenkinsapi.init('myurl',{request: {strictSSL: false}});
I got the following error:
{"statusCode":400,"body":"","headers":{"server":"nginx/1.13.9","date":"Mon, 17 Jun 2019 09:28:34 GMT","transfer-encoding":"chunked","connection":"close","strict-transport-security":"max-age=15724800; includeSubDomains;"},
Thanks in advance.
i have some xml data,
how to create a job by xml data?
After requiring and initializing the library, the data fetch fails:
jenkins.all_jobs(function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
Error:
Uncaught TypeError: self._qs.unescape is not a function
Environment: Windows 10.
Node version: 6.5.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.