ghale / gradle-jenkins-plugin

Gradle plugin to programmatically configure Jenkins jobs.
123 stars 42 forks source link

Recieving 400 Bad Request Creating Jobs inside Folders #37

Closed rizvfe00 closed 10 years ago

rizvfe00 commented 10 years ago

I couldn't find this functionality documented on the wiki. Any plans to make folders a first class citizen as done with the groovy-job-dsl, supporting folders in the name property and folder creation/deletion?

These two jenkins dsl plugins are phenomenal, thanks for the hard work.

I am getting a Bad Request on CloudBees Jenkins. ContinuousDelivery folder exists but the test job I am trying to create does not.

10:50:30.581 [DEBUG] [org.apache.http.impl.conn.DefaultClientConnection] Sending request: >POST /job/ContinuousDelivery/createItem HTTP/1.1 10:50:30.583 [DEBUG] [org.apache.http.headers] >> POST /job/ContinuousDelivery/createItem >HTTP/1.1 10:50:30.584 [DEBUG] [org.apache.http.headers] >> Accept: / 10:50:30.585 [DEBUG] [org.apache.http.headers] >> Content-Length: 588 10:50:30.587 [DEBUG] [org.apache.http.headers] >> Content-Type: application/xml

    def defaultServiceOverrides = { folder, jobName ->
        return {
            create = ["uri": "/job/${folder}/createItem"]
            update = ["uri": "/job/${folder}/job/${jobName}/config.xml"]
            get = ["uri": "/job/${folder}/job/${jobName}/config.xml"]
            delete = ["uri": "/job/${folder}/job/${jobName}/doDelete"]
        }
    }

    jobs {
        build {
            def folder = "ContinuousDelivery"
            server servers.production

            dsl {
                name "Test Job Created From Gradle"
            }
            serviceOverrides defaultServiceOverrides(folder, "Test Job Created From Gradle")
        }
    }

I can create jobs at the root using the gradle plugin

Passing a working config.xml instead of using the dsl builder, throws the same bad request

Using a REST client, I have verified https://XXXX.ci.cloudbees.com/job/ContinuousDelivery/createItem?name=TestJob with the same config.xml in the postbody is working

ghale commented 10 years ago

I'll take a look at this but my immediate guess is that the create override needs a name param:

create = ["uri": "/job/${folder}/createItem", params: [ name: "${jobName}" ] ]

There aren't any plans to make it a first class citizen, but that doesn't mean it shouldn't be. Frankly, there hasn't been much demand for it (just the one issue), and combined with the fact that I don't have easy access to a cloudbees instance, it hasn't been high on my priority list. This is also why it never got into the documentation.

Actually, improving this support would be a great idea for anyone wanting to contribute.

rizvfe00 commented 10 years ago

That worked! Thanks for the quick response, much appreciated. If I get some free time, definitely wouldn't mind adding that functionality into this project.

Thanks again.