Jenkins/Hudson random tips - add password to 'database.yml' using 'sed'

Sed
It's been a long time since the my last blog post :) 

Ok, so i will start with a simple tips . I don't know about you guys, but in my team's Rails projects we made database_example.yml instead of database.yml in our repository ( SVN / git etc ) and write password there. The problem comes at the first time you make a job when the codes are downloaded from repository and you wanna start to build your project using "rake db:migrate" for migration .

Do you see the problem? yup.. the default rails configuration file for database is database.yml but the one that is downloaded from repository is database_example.yml and with no password inserted. And the result is "FAILURE" when building the job because the database.yml don't exist and database password is not filled yet.

The Solution :

  1. Search the text in the database_example.yml that contain "password:" and replace it with "password: yourpassword".
  2. Save it to database.yml

For those operations , we can use 'sed' command. We can use the sed command to change all occurrences of one string to another within a file, just like the search-and-replace feature of your word processor. The sed command can also delete a range of lines from a file. Since sed is a stream editor, it takes the file given as input, and sends the output to the screen, unless we redirect output to a file. In other words, sed does not change the input file.

For this case, see the code below :

Put the code on your Jenkins Build step before running migration . enjoy :)

Panggi Libersa Jasri Akadol

Panggi Libersa Jasri Akadol

I am an open minded person, totally platform agnostic and believe in using the right tool for the right job

Subscribe...

Follow via RSS

Archive

2011 (12)
2010 (56)

Contributors