arangamani / jenkins_api_client

Ruby Client libraries for communicating with Jenkins Remote Access API
http://github.arangamani.net/jenkins_api_client/
MIT License
415 stars 240 forks source link

client.job.list_all throws 404 but curl works fine. #245

Open andrew80k opened 6 years ago

andrew80k commented 6 years ago
require 'jenkins_api_client'

begin
  @client = JenkinsApi::Client.new(:server_ip => 'jenkins.example.com',:server_port => '443',:username => 'user',:password => 'password',:log_level => 0,:ssl => true)
  puts @client.job.list_all
rescue Exception => e
  puts e.message
end

produces:

D, [2017-09-15T08:18:18.546154 #32469] DEBUG -- : GET /api/json?tree=jobs[name]
D, [2017-09-15T08:18:19.272611 #32469] DEBUG -- : HTTP Code: 404, Response Body:
E, [2017-09-15T08:18:19.272756 #32469] ERROR -- : JenkinsApi::Exceptions::NotFound: Requested component is not found on the Jenkins CI server.

Yet I can do:

curl -X GET -u 'user:password' "https://jenkins.example.com/api/json?tree=jobs\[name\]" | python -m json.tool

And get:

{
    "_class": "hudson.model.Hudson",
    "jobs": [
        {
            "_class": "com.cloudbees.hudson.plugins.folder.Folder",
            "name": "ADMIN"
        },
        {
            "_class": "com.cloudbees.hudson.plugins.folder.Folder",
            "name": "CODE_QUALITY"
        },
        {
            "_class": "com.cloudbees.hudson.plugins.folder.Folder",
            "name": "MODERNIZATION"
        },
        {
            "_class": "com.cloudbees.hudson.plugins.folder.Folder",
            "name": "PRE-PROD"
        },
        {
            "_class": "com.cloudbees.hudson.plugins.folder.Folder",
            "name": "SANDBOX"
        },
        {
            "_class": "com.cloudbees.hudson.plugins.folder.Folder",
            "name": "STAGING"
        },
        {
            "_class": "com.cloudbees.hudson.plugins.folder.Folder",
            "name": "TEST-AUTOMATION"
        },
        {
            "_class": "com.cloudbees.hudson.plugins.folder.Folder",
            "name": "UTILITIES"
        }
    ]
}

Jenkins version is:

 X-Jenkins: 2.59

I have been writing a barebones ruby interface for the last day or so, but REALLY don't want to do that.

I assume something is getting mangled, but can't figure out what it is. Any assistance/advice would be appreciated.

katelovescode commented 6 years ago

Hey @andrew80k - I can't duplicate this locally. Both commands get me the same result, which is listing my jobs. This could be related to the fact that jenkins_api_client right now doesn't fully support the folders plugin by CloudBees. We have some in-progress issues dealing with this and it is planned for future functionality, but I'm not sure when.