GithubHelp home page GithubHelp logo

node-jenkins-api's People

Contributors

brianmichel avatar cainslie avatar chamerling avatar enobrev avatar existentialism avatar fgtatsuro avatar hayes avatar huangrurong avatar ianfixes avatar jansepar avatar kbuchacz avatar kub1x avatar larrycai avatar marcells avatar mateusfreira avatar ngotchac avatar patrickstankard avatar pavanmt9 avatar podgorniy avatar raynos avatar rockie-yang avatar thejefe avatar trcjr avatar tzellman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-jenkins-api's Issues

jenkins.configJob

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)?

last_result() is broken

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.

get last_completed_build_info return null

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

error when I use the all_builds

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

how to get buildname used in jenkins.console_output

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 ...."

copy_job doesn't work when using folder name

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

Git Parameter

I have a quetion.
image
Our Jenkins use plugin Git Parameter, and how can I push my selected branch in build_with_parmas?

Node 4 Compatibility Broken Since Refactor

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.

CORS issue

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.

some functions are missing/not available

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?

How to avoid Error: self signed certificate in certificate chain

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.

Delete Build doesn't work

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

Uncaught TypeError: self._qs.unescape is not a function

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

Multibranch Pipeline Jobs

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.

Return date on job info

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.

how to return the build's actions info when use all_builds api?

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

Syntax Error Unexpected End of Input from Jenkins API node.js package

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?

image

Note: We are triggering too more Jenkins job at the same time

Server returned unexpected status code: 403

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)
});

node-jenkins doesn't play well with folders plugin

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?

Crumb support

I don't see any documentation around support for CRUMB. How to make it work for Jenkins that has CSRF protection configured

How to get current running build status is completed or not?

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.

Can't have url special chars in password

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.

Allow users to pass in params that get forwarded to request

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.

JSON.parse occasionally fails

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.

issue using https protocol

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?

fetching error

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)

Cross-Filter :
hc_5

Code to call api :
hc_2

Response in console :
hc_4

Response in web app:
hc_3

NPM Package

It would be really awesome if this were a NPM package.

Browserify errors with Access-Control-Allow-Origin

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?

how to build?

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)
});

Unable to clone repository

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.

create job

i have some xml data,
how to create a job by xml data?

jenkins.build should return the build number too

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.

create_folder fails to create folder

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:

  • how to create nested folders? /my-folder/subfolder
  • how to check that folder exists? is jenkins.get_config_xml() returning non-404 is ok?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.