Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request options #13

Closed
boopathi opened this issue Apr 10, 2015 · 12 comments
Closed

request options #13

boopathi opened this issue Apr 10, 2015 · 12 comments

Comments

@boopathi
Copy link

Add options to override more of the HTTP Request options, like,

  • auth as a separate option {auth: { user: <user>, pass: <pass> } }
  • etc...
@silas
Copy link
Owner

silas commented Apr 10, 2015

You can send in basic auth by just specifying it in the URL.

var jenkins = require('jenkins')('http://user:pass@localhost:8080');

What other option are you looking for? You can modify almost everything about the request if you want, so if you have something particular in mind I give you an example.

@boopathi
Copy link
Author

Yeah. I saw that. I thought it would be better to have them as a part of options rather than constructing the url.

More options like these - https://github.com/request/request#requestoptions-callback. - some of them which makes sense to be overridden by user,

  • timeout
  • proxy
  • strictSSL
  • auth (in object form)
  • headers (which is already there).
  • etc...

@silas
Copy link
Owner

silas commented Apr 10, 2015

So totally not documented, but you can pass any of this through: agent, pfx, key, passphrase, cert, ca, ciphers, rejectUnauthorized, secureProtocol, and timeout.

Auth isn't an object in http.request, it's a string. If you want to pass it along in that form you can send in as a parsed url (https://nodejs.org/docs/v0.12.1/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost) as baseUrl.

Maybe you're thinking about the npm request module? I don't use it so I can't pass along those options.

@boopathi
Copy link
Author

Oh! Thanks, this should work!

@rafaelmagu
Copy link

I found this issue while investigating how to have the module accept self-signed certificates. I need to pass in rejectUnauthorized, but I can't figure out why this isn't working (still getting errors about self-signed cert in chain):

    new JenkinsClient
      baseUrl: "https://user:pass@jenkins_url"
      timeout: 5000
      rejectUnauthorized: false

Can you clarify how to pass the rejectUnauthorized option?

@rafaelmagu
Copy link

To answer my own question, setting an environment variable as per this comment did the trick.

@silas
Copy link
Owner

silas commented Jun 16, 2015

These options are just the normal node https options. In order to use rejectUnauthorized you must pass in an Agent (or disabled it) as the global http agent ignores it by default (obviously you can disable auth globally as well).

See the https.request options for more details (scroll down a bit):

https://nodejs.org/api/https.html#https_https_request_options_callback

Something like the following should work:

new require('jenkins')({
  baseUrl: 'https://user:pass@jenkins_url',
  timeout: 5000,
  rejectUnauthorized: false,
  agent: new require('https').Agent(),
})

@uccmen
Copy link

uccmen commented Jan 21, 2017

@silas How do I initialize a jenkins client using api token?

@silas
Copy link
Owner

silas commented Jan 21, 2017

You just use basic auth and replace your password with the api token, example:

var jenkins = require('jenkins')('http://' + username + ':' + apiToken + '@localhost:8080')

@uccmen
Copy link

uccmen commented Jan 22, 2017

@silas - thank you. It worked locally, but when I tried to get list of jobs from remote server, I received an empty array. When replaced with password in the url - then I get the list of jobs.
Anything else I'm missing? Remote jenkins version is 2.32.1 while my local is 2.19.

@silas
Copy link
Owner

silas commented Jan 22, 2017

I tested on a local version of 2.32.1 and it seemed to work fine. Assuming you're using the same user with the API token and password I can't really say what's wrong. I'd probably contact the jenkins admin, might be some plugin or something that doesn't work with API tokens.

@uccmen
Copy link

uccmen commented Jan 26, 2017

thanks for effort on trying it out @silas . I checked with my ops team and they shared that our jenkins server is behind a proxy... They'll get back to me once they updated some "rules" so I can retrieve jobs using api token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants