Downloads

Introduction

When developing systems often you have local, staging and production servers. On these systems, although the architecture is identical, things like database passwords and names usually differ. Rather than build one workspace with different hardcoded values for each environment you can build one workspace and use scripted parameters to set the values based on the environment you are running in.

Instructions

Let's build a workspace to meet the following scenario. I wish to create a workspace that runs on my local, production and staging servers without changing anything even though the server the database username and password are different.

Create a workspace with a choice published parameter called environment. This parameter has the values local, staging and production.

Create a Scripted (Python) parameter called DB_NAME. Set the Python to the following:

This script is very simple. It does a test to see if the published parameter you set is equal to production, staging or local. Based on this it sets the Database name parameter and then returns it.

You can then use the DB_NAME parameter throughout the workspace and the value will change depending on whether you ran the workspace it using production, local or staging parameter. This can then be repeated for the DB_PASSWORD.

You can then publish the workspace to FME Server and then set your code in your deployment to pass in either staging, production or local depending on the environment as a published parameter.

We use DTAP roadmap to deploy FME Server scripts. Using the solution abowe works fine, however, it requires the maintenance department that deploy the scripts to select a value for the scripted Par. As a variant to the script above, I use the FME Server FME_SERVER_WEB_URL to check on the environment. When the scripted parameter is on top of the list, it can be used by all other parameters to be referenced for database names, file server names, URLs, and other environment dependent parameters. Like the script below:

One could even use os.getenv to have parameters depent on system level environment variables, like: