Send email based on lifecycle

We have two categories of lifecycle - one where the deployment to dev is automated, and another where it needs to be manual, after a given process has been done. What I’d like to do is detect which lifecycle the project is set for, and if it’s “XYZ”, then send an email to the user who checked in the code (TFS -> Octopus via OctoPack) notifying them to deploy the app when that process is complete.

What’s the best way to approach this?

Hi Jeff,

Thanks for getting in touch!

Correct me if I’m interpreting this wrong, but it seems like you want to send an email to the user who checked in the code, but only if the related Octopus Project has a particular lifecycle?

Unfortunately, we don’t set any variables that describe the lifecycle for the project. Because a project can only have one lifecycle, it’s assumed you know what that lifecycle is when you’re configuring the project. So none of the steps in your deployment will be able to retrieve this information (unless you go via the API, which could be tricky) unless you make it available via a variable.

However, I’m assuming from your message that you only want this email to go out if the developer has to manually deploy. That’s a bit of a catch-22 - you can’t trigger an email unless there’s a deployment happening. We don’t expose the ability to run your own tasks outside the context of a deployment.

If the email needs to be triggered from a checkin, you might want to look at sending an email from TFS using the Alerts functionality.

Sorry it’s not better news.

Thanks,
Damian Brady

You’re assessment is correct. Here’s the user story: Some of our projects do not fall within our agile ALM process, and can be deployed immediately. Others need to have their negative tests run first, to validate the problem, before the corrected code is deployed. Thus, some projects will fall w/in one lifecycle, and some w/in the others. I want to avoid modifying the steps between lifecycles – which is why I was asking about the ability to detect.

Adding an alert in TFS does me nothing, since I don’t have the knowledge there about whether or not the particular project can be deployed automatically or not.

Hi Jeff,

Unfortunately you may be out of luck. As I mentioned, we don’t run any steps until a deployment is underway, so sending an email from Octopus isn’t possible when you push a package (unless you’re deploying obviously). You can get the information out of the REST API, but you won’t be able to do it from Octopus without running a deployment.

With respect to setting up an alert, I’m aware TFS doesn’t know anything about Octopus, but I would assume the team member who can set up an alert would be aware of the lifecycle being used for that project? Or are they handled by two separate teams? If so, communication might be your only solution so you only set up the alert for the relevant TFS projects.

Some other ideas that you could try if you’re really enthusiastic:

  • You could write a small intermediate endpoint which uses the REST API to query Octopus to find out which lifecycle the related project uses. You could then use Web Hooks or XML Notifications to hit that endpoint when a build is complete. Of course, you’ll need to know the ID of the Octopus project that corresponds to the TFS project so you can find it.
  • You could configure an additional environment that gets deployed to before your current first environment. You could have an additional step that only runs in that environment and uses the REST API to check the lifecycle then send an email if appropriate.

It’s an interesting scenario, and one I haven’t encountered. Usually there would be no need for behaviour like this as the team working with the code is the same team configuring Octopus, or at the very least they’re in close communication.

Thanks,
Damo