How to get folder name inside deployment package to be stored in a variable

I have to create a deployment process for node.js application packaged using webpack from teamcity and uploaded to Octopus deploy server.

During packaging I have all the content inside folder name something like “Project-21-02-2023” (Project1-DD-MM-YYYY) generated dynamically.

While deployment I have 2 step process:

  1. Copy the content to ‘Custom Install Directory’.
  2. Make an entry in database with the folder-path where file content is placed. (I have to pass the folder-path in SQL query)

I have no issue with 1st step but in 2nd step how I can get the folder name and path placed inside the zip package. Folder name is generated dynamically should be stored in some variable which I can reference in later steps and in SQL query.

I tried writing a custom script for this, as first step below:

Set-OctopusVariable -name "PackageFilename" -value $OctopusParameters["Octopus.Tentacle.CurrentDeployment.PackageFilePath"]
Write-Host "PackageFilename" #{Octopus.Action[Run a Script].Output.PackageFilename}
Write-Host "PackageFilename" #{Octopus.Action['Run a Script'].Output.PackageFilename}

But nothing gets printed. I just tested this to try out. setting the octopus variable. I’m not sure which will give me the folder name.

I’m very new to this, I’m reading docs for any leads but not getting anything specific to this.

Deploying package: C:\Octopus\Files\Waveform@S26@33BC07F96CFA834EAC7EC86276DEBB40.zip

33BC07F96CFA834EAC7EC86276DEBB40.zip >>contains>> “Project-21-02-2023/project-content”

Hi @officeofprashantkumar,

Thanks for getting in touch!

When working with built-in variables like this, it is very useful to add the OctopusPrintEvaluatedVariables system variable to the project with a value of true.
This will then list all the variables and values available to each step within the task log.

I believe you would want to add a custom script to your first step that stores the location as an output variable.
e.g.

Set-OctopusVariable -name "PackageFilename" -value $OctopusParameters["Octopus.Action.Package.CustomInstallationDirectory"]

Then in your second step you should be able to retrieve the value with:

$OctopusParameters["Octopus.Action[Step1].Output.PackageFilename"]

Regards,

Paul

Hi Paul,

Thanks for suggesting OctopusPrintEvaluatedVariables. I could not set the variable using Set-OctopusVariable however I figured out some alternate existing system variables.
Now when I’m supplying the system variable in SQL query, its not evaluated but printed as it is.

Ex. I have to insert the folder path as : ‘/Project/wf/wf_1/index.html’

but value being inserted in database is : ‘/Project/wf/#{Octopus.Action.Package.PackageId}_#{Octopus.Action.Package.PackageVersion}/index.html’

I tried this as well : ,‘/Project/wf/’+#{Octopus.Action.Package.PackageId}+‘_’+#{Octopus.Action.Package.PackageVersion}+‘/index.html’

Please suggest how to provide variables in sql query?

I think I have to update the powershell script for ‘SQL - execute script’ and add few parameters which will be replaced in the query before execution.

Are you using the variables Octopus.Action.Package.PackageId and Octopus.Action.Package.PackageVersion within the step that the package is being deployed in or a later step?

I ask because those variables are only available to the step with the package.
To use them in a later step you would need to include the name of the step where the package is deployed.
e.g.
Octopus.Action[Deploy a Package].Package.PackageId

1 Like

Its use in later step - its third party step for executing SQL script, I’m providing SQL query as string in variable then executing it to make an entry in database.

Hopefully, adding the relevant step name into the variable, like in my example above, will work for you then.

1 Like