DbUp Script Token Replacement


I have a scenario where I’m using a DbUp script to create data in the database. The data needs to be different in each environment.

Is there a recommended way to run a different script, or a different portion of a script based on the Octopus Environment?

I’ve tried this in T-SQL, and it does not appear to work:

IF ‘$Octopus.Environment.Name$’ = 'DevelopmentServer’


The DbUp Variable name is a RegEx match token, so it can’t have the periods in it.

I tried this, and this worked…

            var upgrader =
                    .WithVariable("Environment", "Test")

and then in my script:
IF '$Environment$' = 'Test' INSERT.....

Hello Paul,

Is there any way I can pass Octopus variable name in .WithVariable(“Environment”, “OctopusVariableName”) instead of fixing the value in DbUp.

This way I can do without writing the If conditions in SQL scripts.

Any updates on this?

This will basically allow to use a single nuget package for multiple environments same as is for application deployment.

Hi Altaf,

Thanks for getting in touch.
Unfortunately you can’t get Octopus variables inside your SQL scripts (especially if they are embedded as part of your DBUp assembly).
What I would do in this case is use an appsetting in your config file for your DBUp host and use Octopus variables to set that.