Deploy each version of a package only one time?

We have a package that we would like to change so that the Deploy.ps1 script gets run in each environment exactly once. (The Deploy.ps1 in this package runs a SQL script to clear out “temporary” tables. We’d like to be able to skip it if our schema hasn’t changed.)

The best that I can come up with is to use the Octopus.Deployment.PreviousSuccessful.Id variable, and use the Octopus API to get the deployment/release data and look at the package version there.

(I see that there’s a Octopus.Release.PreviousForEnvironment.Id variable that could potentially let the first API call be skipped and go straight for the release, but it doesn’t say it’s the last successful release.)

Is there a simpler way to get the prior deployed package version for an action that I’m not seeing?

Hi Andrew

Thanks for getting in touch!

If I understand it correctly, you would like to run a SQL script for each version of package exactly once for each environment.

Couple ways come into my mind if that is the case

  1. Make the SQL script idempotent, so that it doesn’t matter how many times it runs.
  2. Get Octopus to keep track of what version of the package has been deployed.

For option 2, you would then need a script step that sets the package version somewhere e.g. in the database by using this variable Octopus.Action[step name].Package.PackageVersion where step name is the name of the step that deploy the package. For any subsequence deployment, Deploy.ps1 will firstly check if the same version has been saved in the database and skip if require.

I hope this helps!

Let me know what you think and how you go.

Regards
Eddy

Unfortunately changes to the SQL script aren’t feasible at this point in time. I’ll go with my original thought of using the API to find the last-deployed package version. Thanks!

Hi Andrew

No problem, please do not hesitate to contact us if you need any more help.

Regards
Eddy

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