Powershell - root directory path

markb's Avatar

markb

10 Nov, 2017 12:20 AM

Part of our front end build process creates a JSON file in the site root. During deployment I need to read that file, but trying these variables returns empty strings. I'm trying to run my script before the site is deployed in a separate "run a script" step

Write-Host $OctopusParameters['Octopus.Action[SIteName].Package.InstallationDirectoryPath'] 
# empty string

Write-Host $OctopusParameters['Octopus.Action.Package.CustomInstallationDirectory']
# empty string

Write-Host $OctopusParameters['Octopus.Action[SiteName].Package.CustomInstallationDirectory']
# C:\site\Web (I don't know how this is set or why it returns this value)

Write-Host $OctopusParameters['OctopusOriginalPackageDirectoryPath']
# empty string

Is there some variable that will return the current site's root directory - the site that I'm deploying? Am I trying to access this directory too early in the process? If so at what point can I access the site's root directory?

Thanks

  1. 1 Posted by markb on 10 Nov, 2017 07:46 PM

    markb's Avatar

    To follow up, if I move this script step after the Deployment then using InstallationDirectoryPath gets the correct path. Is there any way I can access that path before the deployment step?

    I also tried checking the box for "Wait for packages to be downloaded before running" but that didn't help.

    Thanks

  2. 2 Posted by markb on 10 Nov, 2017 08:32 PM

    markb's Avatar

    More attempts. It seems like if the first step is a "Run a Script" step almost none of these variables return anything. I'm just trying to get the current directory where all my files are that are going to get deployed in the next step

    Write-Output ("FilePath: " + $FilePath)
    # c:\Logs\Site.Services.dev
    
    $OctopusParameters['Octopus.Action.Package.InstallationDirectoryPath']
    # empty string
    
    $OctopusParameters['Octopus.Agent.ProgramDirectoryPath']
    # C:\Program Files\Octopus Deploy 30\Tentacle
    
    $OctopusParameters['Octopus.Release.CurrentForEnvironment.Id']
    # Releases-109793
    
    $OctopusParameters['Octopus.Release.CurrentForEnvironment.Id']
    # Releases-109793
    
    $OctopusParameters['Octopus.Action.Package.CustomInstallationDirectory']
    # empty string
    
    $OctopusParameters["OctopusOriginalPackageDirectoryPath"]
    # empty string
    

    Thanks again!

  3. 3 Posted by markb on 10 Nov, 2017 10:06 PM

    markb's Avatar

    I got it! This is the correct path I misread the deployment step and thought it should be going to a different location.

    $OctopusParameters['Octopus.Action[Catalog].Package.CustomInstallationDirectory']

  4. Support Staff 4 Posted by Reece Walsh on 13 Nov, 2017 03:37 AM

    Reece Walsh's Avatar

    Hi Mark,

    Thank you for contacting Octopus Deploy support in regards to this query,

    It's great to hear you have a solution in-hand, I appreciate you taking the time to update the ticket with your breakdown on the issue.

    If you require any assistance in the future please do not hesitate to reach out :)

    Kind Regards,

    Reece

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

Generic

? 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