Use API to add the same email notification step at the end of all projects?

I have ServiceNow setup to parse the subject and contents of emails sent from Octopus so that the version field for the deployed application is updated each time a deployment finished successfully. Since there are hundreds of projects I am looking to do this via script/API but have had minimal luck finding anything useful so far. Any help with pointing me in the right direction would be appreciated.

The AddMissingStepsToProcess.ps1 script gets me part way there. Are there any scripts that give an example of creating an email notification step?

Hi @gmullins,

Thanks for getting in touch! Depending on your requirements, our Subscriptions feature may be a more accessible option. If you’re only trying to get the release version for any given project and environment, then this feature would be a perfect fit. You can configure it for webhook subscriptions and send a JSON payload directly to your ServiceNow server when a Deployment Succeeded event is registered by the Octopus server.

If you’re looking to get more granular information about the deployment such as package versions, then the email route that you have suggested may be the best option. The AddMissingStepsToProcess.ps1 is a great option and I’m glad that you’ve found our public script repository, it’s an excellent resource! I noticed that this particular script uses the Octopus.Client. I think it’s easier to create new steps via the client as it does a lot of the heavy lifting and gives you some more feedback if you’re missing any required information.

Personally, when trying to add a new step with the API, I find the best option is to have one step manually created that you can get and inspect the structure of.

For example, I got the deployment process for a project I have an email step on then nested into it to see the construction of its constituent parts.

$project = $repositoryForSpace.Projects.FindByName("Some Deployment").DeploymentProcessId

$deployProcess = $repositoryForSpace.DeploymentProcesses.Get($project)
$deployProcess  # Shows entire deployment process for the project
$deployProcess.Steps  # Now a list of the steps (actions)
$deployProcess.Steps[4].Actions   # My email step was the 5th (zero indexed)
$deployProcess.Steps[4].Actions.Properties['Octopus.Action.Email.Body'].Value  # Here's the email body of that step.

It’s worth noting, the entire deployment process needs to be saved back, even when just editing a single part of one step in it.

I hope this information helps to get you moving in the right direction. If you have any questions at all on this or run into any issues, please don’t hesitate to reach out.

Best regards,

1 Like

Thank you for the great reply! There was some great info for me to look into and I decided to go the subscription route since the only thing I am wanting to get is the Project that was deployed, the release version and the date.

We recently updated our Octopus server to the latest version. Would I be able to use the ServiceNow integration part to establish the connection to our ServiceNow instances and then use that to send the subscription notifications?

Hi @gmullins,

Thanks for getting back! Our ServiceNow integration currently requires an enterprise license to use.

Unfortunately, it doesn’t look like your company is currently an enterprise tier customer. Now, I’m by no means sales rep, but if this feature and the others available via an enterprise license sound like they have a good cost-to-value benefit, it could be worth looking into upgrading. You can estimate the cost increase with our pricing overview page. I’d perhaps contact if this is something your company may be interested in or if you have questions relating to anything licensing.

So, assuming you intend to stay on your current license, I’d say subscriptions does sound like a good fit for your needs here.

If you would like any further advice on this, or have any technical questions at all, please don’t hesitate to let me know. I’d be happy to help however I can.

Best regards,