Environment variables

Hello, I am new Octopus user, trying to discover octopus. I hope you understand my question. English is not my native language.

I have a question about the Octopus env. variables. I have created serveral powershell based steps to deploy docker containers in a dev and a test environment. But the setup of the docker engine (servers, path, locations, etc) differs between the different environments: “dev” is my notebook, “test” is a server.

How can I determine the location ( for example: on my laptop (running a octopus agent)) where a github packages (containing: dockerfile) is downloaded and extracted.

In the Octopus steps I have configured/created for my project; I currently use fixed paths. These fixed path are not identical in all environments. If possible I hope that I can you somekind of Octopus environments variables to make a deployment flexible; so that a step can be used in dev and in test (on different servers)

Is this possible??

My basic workflow:

  1. My first step is to pull a dockerfile from a github repo. After this step is can see the local file location in the release information.
    == ==
    AC Version Location
    June 11th 2018 09:58:48
    Info

June 11th 2018 09:58:48
Info
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll
June 11th 2018 09:58:48
Info
Repository will be cloned to: D:\Octopus\Applications\GitPull\Development\Build&Deploy a Dockerbased container\Pull this container
June 11th 2018 09:58:48
Info
Reinitialized existing Git repository in D:/Octopus/Applications/GitPull/Development/Build&Deploy a Dockerbased container/Pull this container/.git/
June 11th 2018 09:58:49
Info
Fetching remote repository
June 11th 2018 09:58:50
Info
Check out branch master
June 11th 2018 09:58:50
Info
HEAD is now at 2536321 nieuw plaatje
June 11th 2018 09:58:50
Info
Repository successfully cloned to: D:\Octopus\Applications\GitPull\Development\Build&Deploy a Dockerbased container\Pull this container
== ==

  1. Second step is building the container; based on the location discovered in step 1; this is a currently fixed location in a powershell script.
    == ==
    d:
    cd “D:\Octopus\Applications\GitPull\Development\Build&Deploy a Dockerbased container\Git - Pull (HTTPS)”
    docker build --rm -t websiteinadocker .
    cd
    == ==

Is it possible to determine the path of the pulled and extracted github packaged??

Grtz Fred

Hi Fred,

Thanks for getting in touch! Your English is great by the way. :slight_smile:

You can certainly configure different variable values to be used in different environments. This is done in Octopus using the concept of scoped variables. This will allow you to define a single variable name with multiple values, and depending on the scoping of these individual values, they can be evaluated differently depending on where you’re deploying to (i.e. scoping to environments).

As an example, I’ve created a variable named Location which has different values and scoping.

This would then allow you to bind this variable to your PowerShell script to change directory during deployment to your environment-specific location:

cd "#{Location}"

If needed, you can also set output variables in a step which allows this value to be retrieved in subsequent steps. Using PowerShell, you can set the output variable in step 1 like so: Set-OctopusVariable -name "Location" -value "D:\Octopus\Applications\.... It can then be retrieved in step 2 using variable binding syntax like so: #{Octopus.Action[Step1Name].Output.Location} or in other scripts like this: $variable = $OctopusParameters["Octopus.Action[Step1Name].Output.Location"].

Additionally, there are some built-in system variables which are set automatically that are available for use. You can refer to our documentation which outlines all of these.

I hope this helps! Don’t hesitate to reach out if you have any further questions going forward.

Kind regards,

Kenny

Hi!!

I am going to test it!!

Hi Fred,

That’s great to hear! Let me know how your testing goes, and if you have any further questions going forward don’t hesitate to reach out! :slight_smile:

Kind regards,

Kenny

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.