Access to Built-in variable from a powershell step

Hi,

Is it possible to get access to the location of the deployed package in a powershell step, the following output seems to indicate that those variables are blank. Also because the step’s script is running from a temporary location it’s not possible to know where the package install location is.

2013-02-21 01:35:14 INFO Begin script run
2013-02-21 01:35:14 DEBUG Running script against tentacle http://wsn-wcmsdev01:10933/
2013-02-21 01:35:28 ERROR Running job on the tentacle failed:
2013-02-21 01:35:28 INFO Tentacle output follows:

2013-02-21 01:35:22 INFO OctopusWebSiteName=wwwdev
2013-02-21 01:35:22 INFO OctopusOriginalPackageDirectoryPath=
2013-02-21 01:35:22 INFO OctopusPackageDirectoryPath=
2013-02-21 01:35:25 INFO ERROR: & : The term ‘_deploy\ReplaceOctopusConfigVars.ps1’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
2013-02-21 01:35:25 INFO ERROR: At C:\Windows\system32\config\systemprofile\AppData\Local\Tentacle\Temp\a40954a1-060b-419a-9446-297b48843721.ps1:4 char:3
2013-02-21 01:35:25 INFO ERROR: + & $OctopusOriginalPackageDirectoryPath_deploy\ReplaceOctopusConfigVars.ps1 | Wr …
2013-02-21 01:35:25 INFO ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2013-02-21 01:35:25 INFO ERROR: + CategoryInfo : ObjectNotFound: (_deploy\ReplaceOctopusConfigVars.ps1:String) [], CommandNotFoundException
2013-02-21 01:35:25 INFO ERROR: + FullyQualifiedErrorId : CommandNotFoundException
2013-02-21 01:35:25 INFO ERROR:
2013-02-21 01:35:26 INFO ==============================================
2013-02-21 01:35:26 INFO PowerShell exit code: -12
2013-02-21 01:35:26 INFO ==============================================

Hi Brendan,

A deployment can contain multiple steps for multiple packages and scripts. Each package can be installed to a different place depending on the variables and whether it has been installed before on that machine. If you’re deploying to 12 machines, each might even use a different path. Currently, a “script step” isn’t passed any information about a “package step” that ran before it because there would be too many conflicting values to use (because of the many machines you could be deploying to).

If you wanted some certainty, you could have some variables like:

  DeployPackageABCTo = C:\Apps\Foo\#{OctopusReleaseNumber}
  OctopusPackageDirectoryPath = #{DeployPackageABCTo}  scope=PackageABC

This tells package ABC to be installed to a path based on the current release number. You can then use the same value (available in your script step as $DeployPackageABCTo) to get the same path.

Or, have a PostDeploy.ps1 script in your package that either does whatever is currently done in your Script step, or writes $OctopusPackageDirectoryPath to the registry/a file on disk, and have your script step pick up that value.

Hope that helps to a) explain why the values aren’t available, and b) provide a solution.

Paul

Thanks for the explanation Paul, makes total sense now