This is somewhat similar to http://help.octopusdeploy.com/discussions/questions/10040-how-to-get-the-package-in-a-server-side-script
What I want to achieve is to be able use msdeploy.exe from a C# script to directly sync a zip package (in this case, an web deploy package created by msbuild). My reasons for wanting to use msdeploy directly are mostly around flexibility and the ability to specify the package parameters that are passed into the command line.
I definitely want to leverage Octopus’ ability to trigger deployments based on new packages being published (currently using the built-in repo) so it appears that I need at least one step which consumes a feed. Unfortunately I cannot see any way to do this without adding one of the built-in Octopus steps, such as Deploy a Package. The Deploy a Package step provides the desired “Package Feed” and “Package ID” parameters which I want to use, but (understandably) it wants to deploy said package to a Deployment Target.
Unless I’m barking up the wrong tree here, I don’t actually want or need deployment targets for this proposed process so I’m currently adding a dummy target and a dummy environment which I choose not to deploy to, in addition to my actual environments (e.g. Test, UAT, etc). That way when I choose to deploy to my Test environment (let’s say this is Azure) it actually skips the Deploy a Package step but still gives me access to the Octopus Parameters indicating the correct package ID, e.g. my C# script works:
var packageId = Octopus.Parameters["Octopus.Action[Package].Package.PackageId"];
var packageVersion = Octopus.Parameters["Octopus.Action[Package].Package.PackageVersion"];
var packageName = packageId + "." + packageVersion;
var packagePath = $"C:\\Octopus\\Packages\\{packageId}\\{packageName}.zip";
const string msdeploy = "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy";
var cmdArgs = $@"-verb:sync
-source:package='{packagePath}'
-dest:auto,ComputerName='https://{azureSiteName}.scm.azurewebsites.net/msdeploy.axd?site={azureSiteName}',UserName='${azureSiteName}',Password='{azurePassword}',AuthType='Basic'
-enableRule:AppOffline
-setParam:name='IIS Web Application Name',value='{azureSiteName}'";
// ...
// append other web deploy parameters
// ...
cmdArgs = cmdArgs.Replace(Environment.NewLine, " ");
var process = new Process();
var startInfo = new ProcessStartInfo(msdeploy, cmdArgs)
//...
However, it’s still not right as there is the potential for someone to attempt to deploy to my “dummy” environment.
I realise that Octopus started out with fairly specific use case of extracting and deploying nuget packages and was later extended to support Azure deployments but I’m hoping that there might be some room for movement here as I can see a number of other similar scenarios where I want to leverage Octopus’ built-in repository, wonderful UI and excellent custom step functionality.