It's common to have multiple projects in Octopus that need to do the same tasks during deployment, such as configuring IIS. Copy and pasting the scripts is certainly one approach, but not ideal. In this guest post, Jonathan Goldman shows us his technique for sharing a useful library of PowerShell scripts with his Octopus projects.


Recently we’ve been moving more and more of our projects to Octopus Deploy and one of the things that quickly became apparent is that there is a need to share the same deploy scripts across multiple projects, for example installing a service, setting up a windows schedule or configuring an app pool. Things can get messy pretty quickly as scripts are copy and pasted between projects, so we looked for a simple solution.

To solve the problem I created an internal nuget package which contains our deploy scripts along with an Init.ps1 step to copy them to a solution folder. We can then add the scripts to the projects that need them and reference them from our Octopus Deploy.ps1 scripts. When a script is changed I can just update-package and get all the latest changes.

As it turns out a lot of the scripts we create end up being pretty generic, so I created a nuget package that everyone can take advantage of:

install-package BuildDeploySupport

If you add DeployWeb.ps1 as a link to your web project (Add Existing Item -> Add As Link). And edit your Deploy.ps1 to look like the following

. .\DeployWeb.ps1

InstallAppPool 'my-app-pool' 'v4.0' {
    SetCredentials 'username' 'password'
}

InstallWebSite $OctopusWebSiteName 'my-app-pool' 'www.yourdomain.com' {
        SetWindowsAuthentication $true
        SetAnonymousAuthentication $false        
}

You'll no longer have to log in to your server to configure your app pools or create websites. Everything should just work. This is similar to the approach outlined in the Octopus documentation.

This should not only help people get started with Octopus but also help foster a community around creating reusable deploy scripts.

If you're interested in contributing everything is open source and available on github:

https://github.com/jonnii/BuildDeploySupport


Octopus Deploy is used by thousands of developers across the globe, from small companies to large enterprises. Find out if it meets your deployment automation needs by taking advantage of our free 30-day trial. You can spin up an instance with just a few clicks!

Community Integration Walkthrough