Automating Jenkins Deployments with Chef

61 views
Skip to first unread message

Kenneth Baltrinic

unread,
Jan 12, 2015, 7:46:06 AM1/12/15
to jenkins...@googlegroups.com
I am working on creating a chef cookbook to automate our Jenkins infrastructure.  I am using the opscode Jenkins cookbook as my starting point but it only has a few basic resources.  I can see I am going to need use the cookbook's jenkins_script resource to configure Jenkins via groovy. 

That would be fine except I am having considerable difficulty figuring out how to configure Jenkins via groovy.  There does not seem to be a lot of information out there either in the Jenkins docs nor in blogs, etc.  None of the plug-ins document their API, etc.  There are API docs for main Jenkins which help but only if you already understand the big picture, which is what I am struggling with right now.  I understand how to configure all of our Jenkins boxes via the UI, but how do I learn to translate that into knowledge of writing groovy scripts?  Right now the only means I am seeing is to spend a very long time digging my way through the source code itself and learning from trial and error.  Is there another way? 

How do people out there learn and use the Jenkins API?

Christopher Orr

unread,
Jan 15, 2015, 9:50:54 PM1/15/15
to jenkins...@googlegroups.com
Hi there,

On 01/12/2015 01:46 PM, Kenneth Baltrinic wrote:
> I am working on creating a chef cookbook to automate our Jenkins
> infrastructure. I am using the opscode Jenkins cookbook as my starting
> point but it only has a few basic resources. I can see I am going to
> need use the cookbook's jenkins_script resource to configure Jenkins via
> groovy.

What are you trying to configure via Groovy? Quite a lot of stuff can
be done via the REST API or the CLI, but using the Groovy console
generally seems more suited to fairly low-level operations.

I know it's not Chef, but have you seen the Puppet module for Jenkins?
Likely there are some insights to be found in its code:
https://forge.puppetlabs.com/rtyler/jenkins


> That would be fine except I am having considerable difficulty figuring
> out how to configure Jenkins via groovy. There does not seem to be a
> lot of information out there either in the Jenkins docs nor in blogs,
> etc. None of the plug-ins document their API, etc. There are API docs
> for main Jenkins which help but only if you already understand the big
> picture, which is what I am struggling with right now. I understand how
> to configure all of our Jenkins boxes via the UI, but how do I learn to
> translate that into knowledge of writing groovy scripts? Right now the
> only means I am seeing is to spend a very long time digging my way
> through the source code itself and learning from trial and error. Is
> there another way?
>
> How do people out there learn and use the Jenkins API?

Trial-and-error is probably the most common way :) But this mailing
list and the IRC channel are good resources too.

But when you say you're struggling with the big picture, what are you
trying to do? Plugins generally don't need to be configured, especially
not via Groovy scripts — most plugin configuration is done per-job and
so is bundled with with config.xml for the job.

You should be able to get pretty far by building the config you want in
the web UI, exporting the config XML via
$JENKINS_URL/job/$JOB_NAME/config.xml, which you can then later POST to
the REST API in another Jenkins instance.

Regards,
Chris

Kenneth Baltrinic

unread,
Jan 27, 2015, 8:39:58 AM1/27/15
to jenkins...@googlegroups.com
Chris,

Thank you for your reply.  Yes, I am using the copy config.xml approach for a lot of scenarios but it seems like a back door approach.  I would have more confidence in the robustness of my code if I were using an API that threw errors when I did things wrong rather than potentially write some bad xml that either breaks jenkins all together (i've had it refuse to start a few times) or misbehave is subtle ways.

All that said though, to answer your question about specific examples, here are two of my other posts on things I am trying to configure in Jenkins via groovy.  


In the case of the former, I am presently using an xml template as the solution.  In the latter case, I have not go there yet as there does seem to be hope of getting the API to work. (fingers crossed).

--Ken
Reply all
Reply to author
Forward
0 new messages