Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I store Jenkins configuration in the project repo (like Travis CI)?

Tags:

How do you maintain the Jenkins job configuration in SCM along side the source code?

As source code evolves, so does the job configuration. It would be ideal to be able to keep the job configuration in SCM, for the following benefits:

  • easy to see who a history of the changes, including the author and the description
  • able to rebuild old branch/tag by checking out the revision and build just work
  • not having to scroll through the UI to find the appropriate section and make change

I see there is a Jenkins Job Builder plugin. I prefer a solution along the lines of Travis CI, where the job configuration is maintained in a YAML file (.travis.yml). Any good suggestions?

Note: Most of our projects are using Java & Maven.

like image 624
Charles Avatar asked Feb 03 '15 04:02

Charles


People also ask

Where does Jenkins store its configuration?

Jenkins stores the configuration for each job within an eponymous directory in jobs/. The job configuration file is config. xml, the builds are stored in builds/, and the working directory is workspace/.

How do I save Jenkins configuration?

Use the UI of the current system to install and configure the plugin. Click Apply >> Save to save the configuration. Use Manage Jenkins >> Configuration as Code >> View Configuration to view the JCasC file with the plugin configured. Click on Download Configuration to save the modified configuration file locally.

Does Jenkins support configuration management?

The Jenkins configuration is managed through XML files, which provides considerable flexibility and allows you to make changes on the fly. The best use case here is to facilitate automation. If you want to automate a few tasks using some automation script, then the best way is to use the Jenkins REST API.

How do I change Jenkins configuration?

So one can get the various configuration options for Jenkins by clicking the 'Manage Jenkins' option from the left hand menu side. Click on Configure system.


1 Answers

Update 2016: Jenkins now provides a Jenkinsfile which provides exactly this. This is supported by the core Jenkins developers and actively developed.

Benefits:

Creating a Jenkinsfile, which is checked into source control, provides a number of immediate benefits:

  • Code review/iteration on the Pipeline
  • Audit trail for the Pipeline
  • Single source of truth for the Pipeline, which can be viewed and edited by multiple members of the project.

I've written a plugin that does this!

Other than my plugin, you have some (limited) options with existing Jenkins plugins:

Use a single test script

If you configure your Jenkins to simply run:

$ bash run_tests.sh 

You can then check in a run_tests.sh file into your SCM repo and you're now tracking changes for how you run tests. However, this won't track configuration of any plugins.

Similarly, if you're using Maven, the Maven Project Plugin simply runs a specified goal for your repo.

The Literate Plugin does allow Jenkins to run the commands in your README.md, but it hasn't yet been released.

Track changes to Jenkins configuration

You can use the SCM Sync configuration plugin to write configuration changes to SCM, so you at least have a persistent record. This is global, across all projects on your Jenkins instance.

There's also the job config history plugin, which stores config history on the filesystem.

Write Jenkins configuration from SCM

The Jenkins job builder project you mentioned lets you check config changes into SCM and have them applied to your Jenkins instance. Again, this is across all projects on your Jenkins instance.

Write Jenkins configuration from another job

You can use the Job DSL Plugin with a repo of groovy scripts. Jenkins then polls that repo, executes the groovy scripts, which create job configurations.

Discussions

Issue 996 (now closed) discusses this, and it has also been discussed on the mailing list: 'Keeping track of Hudson's configuration changes', and 'save hudson config in svn'.

like image 81
Wilfred Hughes Avatar answered Sep 28 '22 09:09

Wilfred Hughes