Running a migrator console application on octopus server

kevin's Avatar


08 Jan, 2018 08:28 PM

I am attempting to use a Teamcity/Octopus setup to deploy my application. The two packages I'm pushing to octopus are an MVC project (which I am deploying to azure) and a Migrator console application project. The Migrator project is a simple exe that just asks yes or no if you want to run migrations and then runs them.

My question is about running the Migrator project. My thinking so far is that I will need to write some powershell, presumably to download the package, unzip it, and then run the exe. This will all be done in the run a script step. Can you let me know if I am on the right track with that? And if I am then any help with how the powershell might look would be appreciated since I am very inexperienced.

Also as for the teamcity side of things should I be using octopack for the Migrator project like I do with the MVC project?

My octopus version is 3.17.6

  1. Support Staff 1 Posted by Shane Gill on 09 Jan, 2018 12:48 AM

    Shane Gill's Avatar

    Hi Kevin,

    Thanks for getting in touch. I think you are on the right track, but it might be easier than you imagine.

    You can package your Migrator project with OctoPack or zip it. You can run the Migrator console app by using the "Run a script" step or "Deploy a package" step.

    Using the "Run a script" step, create a PowerShell script in your project that calls the Migrator. Add the "Run a script step" to your deployment process and specify that you would like to execute a script file found in a package. Octopus will push the package for you and execute the script.

    Using the "Deploy a package" step, specify your Migrator package and add the "Custom deployment steps" feature to the step. Enter a "Post-deployment script" that executes the migration.

    The difference between the two approaches in that the "Run a script" step will be cleaned up after the run, whereas "Deploy a package" will keep the package deployed after the migration has completed.

    I hope this helps.


  2. 2 Posted by kevin on 09 Jan, 2018 08:00 PM

    kevin's Avatar

    Hi Shane,

    Thank you for your thorough explanation. I was able to run my Migrator using the "Run a script" step.

    My problem now is that migrations fail since I am unable to use the correct configuration file for my environment. The file I would like to use is appsettings.Develop.json, while the file that it is choosing is the default appsettings.json.

    Is this something that I do not have control of if I choose "Run a script" as opposed to "Deploy a package?"

    That is the last problem I have to solve for this project to work.


  3. Support Staff 3 Posted by Shane Gill on 09 Jan, 2018 10:54 PM

    Shane Gill's Avatar

    Hi Kevin,

    The choice of which appsettings file to use depends on the value of the environment variable ASPNETCORE_ENVIRONMENT. Octopus does not set this variable. If you would like to set it to match the current Octopus environment, you could add some PowerShell like the following to your script:

    $env:ASPNETCORE_ENVIRONMENT = $OctopusParameters["Octopus.Environment.Name"]


  4. 4 Posted by kevin on 09 Jan, 2018 11:09 PM

    kevin's Avatar

    Yep, that was it. Thank you for all your help.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac