Search code examples
octopus-deploy

Setting environment variables in Octopus


I'd like to specify an environment variable, so I could verify whether it's a stage/production/development environment (either ASPNETCORE_Environment or a custom one). Does Octopus do it by default or do I have to set it up manually?


Solution

  • During the deployment the variable #{Octopus.Environment.Name} will resolve to the name of the Octopus Environment you are deploying to. Following the image below:

    • If you deploy to environment (1), #{Octopus.Environment.Name} will resolve to Development.
    • (2) -> Staging
    • (3) -> Test

    OctopusEnvironments

    But this variable will only be available within the context of the Octopus deployment. If you are looking to set something more persistent you're gonna have to Powershell your way through it using a script step in your deployment process with the below:

    [System.Environment]::SetEnvironmentVariable("MyPassword","P4$$w0rd123", [System.EnvironmentVariableTarget]::Machine)
    

    More info about the above command in this blog post