secondary output stream of a software developer

Automating MySQL Setup for Jenkins Jobs

Creating databases is one of those repetitive tasks when setting up continuous integration for a project. At work we use Jenkins. So we've developed the jenkins-mysql-job-databases-plugin to automate the required steps.

The plugin creates a database and a user for the job, granting access only to the job's database. User credentials and database name are exported to environment variables, which is a great fit with the ciconfiggenerator gem we saw in a previous post. In a Rails project, for example, you could commit the following file to wire everything up:

  adapter: mysql2
  encoding: utf8
  database: %{MYSQL_DATABASE}
  username: %{MYSQL_USER}
  password: %{MYSQL_PASSWORD}

The plugin itself is written in Ruby. Since it is unclear how to handle global configuration options in Ruby plugins, the credentials of the MySQL user that creates databases and grants access are hard coded in the plugin at the moment. Apart from this caveat, the plugin has worked well for us so far.

comments powered by Disqus