YAMLConfig

Derick Bailey edited this page Dec 4, 2010 · 11 revisions

Many of the rake tasks in Albacore support the ability to configure attributes via an external YAML file. This is useful in scenarios where different environments need to have different configuration settings, while still maintaining the core rake file in version control.

For example, if developers are working on their own local copy of a database, they may want to configure the SQLCmd task with their own local database connection information. However, they will not want their local connection information stored in the master rakefile because that would break the build automation server and/or other developers that pull down the file from source control. To facilitate this situation, call the .configure method on an Albacore task that supports it, and load your configuration from an external yaml file.

YAML Auto-Configuration

Albacore will automatically search for a lowercase .yml file named after the task being run, and use the data in that file to configure your task. If the file is not found, it will continue on normally. After the yaml file has been loaded (or skipped), your regular task definition code will be called. You can override anything that the yaml file set during the standard task definition code.

Naming Your YAML File, Per Task

Almost all Albacore tasks support the YAML auto-configuration. To make use of this feature, you need to name the yaml file based on the name of the task. For example, if you create a task as mbsuild :compile do ... end then you would name the yaml file compile.yml

YAML Manual Configuration

In addition to the auto-configuration, YAMLConfig also supports a manual configuration option, which allows you to specify any valid .yml file in any location.

Example: manually configure SQLCmd via YAMLConfig

The SQLCmdTask supports configuration via YAML files. To do this, call the .configure method and provide the location of the yml file.

desc "Create the initial R1 database"
  sqlcmd :create_initial_db do |sql|

  sql.configure("sqlcmd.yml")

  sql.variables :New_DB_Name => "Albacore_Test"
  sql.command_directory = "SQLScripts\\Database\\Db_R1_scripts\\CreateDB"
  sql.scripts "RunCreateDatabase.sql"
end

The contents of the yml file should be name: value pairs that represent the sqlcmd settings and values for those settings. For example, in the above example, the server, database, username and password can all be specified through this yml file:

sqlcmd.yml

command: sqlcmd.exe
server: some_server_name
database: some_database
username: some_user
password: shh!!! it's a secret!