Geeks With Blogs

Alex Hildyard

If you’re writing Step templates, here are some things you may want to consider.

 

* Write a script you can run inside or outside of Octopus

There are two reasons why you're unlikely to code substantial scripts within the Octopus IDE itself. First off, you don't get the Intellisense and completion you get with the Powershell ISE. Secondly, there's no kind of a scratchpad for debugging scripts in Octopus itself: the only way you can test your code is to create a release, pick the step or steps you want to test, and deploy it to an environment. There's nothing wrong with that, but in my experience it does tend to mean that Octopus finds itself the recipient of scripts you've already developed and debugged elsewhere, rather than the place your coding efforts begin.

While that might be unfeasible, I'd note parenthetically that there will always be a place in the market for third party tools that offer some of the development and/or debugging niceties of your favourite IDE, without tying you into a formal project structure. That's what makes LINQPad so great, but before that there were tools like The Regulator, Snippet Compiler, ScriptCS and CS-Script.

So how do you ensure your scripts work both inside and outside Octopus? All but the most trivial Step templates are going to be parameterised, which means you'll be working with the $OctopusParameters hashtable. That's not going to be available outside of Octopus, so what do you do? Daniel Little suggests one approach here. He adds a helper method Get-Param, which checks for the existence of the $OctopusParameters object. If it finds it, it retrieves the parameter of your choice; if it doesn't, it calls Get-Variable to pull back a standard Powershell variable. This is great, but if you structure your Step templates a certain way -- as I'll show you in the next section -- you may not need to do this after all.

 

* Let Step templates call Library scripts; then you can use either

Now I have a particular way that I want to use Octopus, which goes back to the days when I used to use Nolio to deploy applications. I want reusable Step templates that expose nice pieces of modular functionality (eg. creating websites, downloading artefacts from TeamCity, etc.), and I want to back those Step templates with reusable scripts inherited from the Script libraries I choose to include in my project. There's a three-fold reason for this. Firstly, this means I can EITHER use a Step template in my workflow, OR I can use a script (I'll go into the reasons why you might want to choose one approach rather than the other in a subsequent post). Secondly -- and more importantly -- I know that behind the scenes the same code is being called, so that if someone finds a bug in my implementation of (say) a script to copy files and folders, I only need to fix the code in one place. I think that's pretty critical. Thirdly and finally, you can develop and test your scripts outside of Octopus without having to worry about the OctopusParmeters hashtable, because this is now handled in your Step template; your script remains blissfully ignorant of the way in which it was invoked.

 

* Writing scripts once gives you more workflow options

There's also a subtler reason why it really helps to put the bulk of your deployment functionality into Powershell scripts rather than Step templates: Octopus Deploy offers only the most rudimentary of workflows, which execute from beginning to end, and then stop. You can't easily add decision points, and you certainly can't make your workflows re-entrant. And if you decide you want to refactor a workflow (and, trust me, you'll want to do this a lot), you can't compress a set of parent steps by turning them into child steps, or expand a set of child steps back into parent steps, or shuffle child steps between different parents. You have to delete and re-code each step you want to change.

However, that's just how the UI works, and you don't have to do things that way. Think about things like this: Octopus provides ONE workflow through the deployment, but that doesn't mean you can't create a much more sophisticated workflow; you just need to code your sophisticated workflow within the comparatively unsophisticated workflow container that you were supplied. And what *that* means is, if you build up a decent script library, there's no reason that your Step templates need to perform single and trivial activities. Within the confines of any particular template, they can loop, branch, and do anything you like. I find this particularly useful when I have, say, a common deployment script that I want to apply to half a dozen different deliverables. Rather than instantiate the same Step template six times, plugging in almost identical parameters, I loop around inside a single template, doing the things I need. This way, I have a few system-wide steps with names like "Shut down Websites", which are trivial refactorings of what were previously steps like "Shut down IIS on App server", "Shut down IIS on Web server", etc. Note that I'm not advocating in general that you make your steps any less granular than you might otherwise have done. What I'm saying is that for a deployment tool to work effectively you need to match the granularity of your deployment steps with that of the particular deployment activity you are trying to perform within them. With one project, for example, I used a Step template to mark up each key in my web.config file. Once I got to half a dozen keys, I realised that this was a waste of a Step template, so I replaced it with the more generic step "Mark up Config files" -- within which I then pasted in my half dozen calls to Markup-ConfigFile.

 

* Use naming conventions for your parameters

As I've mentioned in a previous post, Octopus Deploy has a few vagaries wrt. parameter resolution. If you can come up with a naming convention for your parameters, and then stick to it, it'll save you a lot of confusion.

 

* Scripts which don't quite succeed should fail

What do I mean by this quixotic statement? I mean that you should always set -ErrorAction Stop at the top of your script, and then individually handle the errors you know about (either with a try/catch or a SilentlyContinue). Yes, initially this makes for whiny, temperamental scripts, but if you stick with it, they grow into mature, dependable adults. Pragmatically, I'd always rather have a script that complains about nothing than one that claims to have done something that in reality it hasn't. When something is deployed wrong, the deployment log is your first port of call, and if you can't trust the detail inside that log, you will be in a world of pain.

Posted on Saturday, January 17, 2015 4:47 PM | Back to top


Comments on this post: Effective Step template design in Octopus Deploy

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Nice post. I was curious about your second bullet. Using a step like "Create Web Site" as an example... Are you saying you create a generic PS method called "Create-WebSite", then call it in your Step Template? So the step template code would look something like this?


Create-WebSite -Name $OctopusParameters["Name"]


Left by Jason Capriotti on Jan 28, 2015 5:45 PM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
I was also curious about how to call functions that are in the Library script modules from a step template, "reusable scripts inherited from the Script libraries"?
Left by -Mark on Jun 10, 2015 7:49 PM

# Re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Enhancing your development workflow is one of the most vital things a developer can do. Homework clock able to control your tools fast and professionally lets you spend your time working on real development instead of aggressive your tools or doing boring, repetitive things.
Left by Alina Olive on Jun 06, 2017 8:20 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Step formats are worldwide over all ventures and they are shown as ventures on the include step page. They are not included as a component of a Run a script step. To take in more about how to utilize step formats with have this Web Development Company .I trust that makes a difference
Left by Ammara Malik on Jul 01, 2017 6:31 PM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Thanks for the step by step instruction. It really helped me to understand more about Effective Step template design in Octopus Deploy. I didn’t have the slightest idea it could be done so easily using PowerShell, I have taken a long and complex approach to achieve the same result. Small Prefab Home
Left by Taylor Shaw on Jul 31, 2017 12:19 PM

# Step Templates
Requesting Gravatar...
Octopus step formats are reusable strides in light of the inherent strides with your own particular parameters and directions Do My Assignment Octopus underpins two sorts of step layouts. Custom stride formats and group step layouts.
Left by Alicia Gill on Sep 13, 2017 12:40 PM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Get free Janampatri in hindi generated by Hindi Kundli Software.
Left by Sanjay Jumaani on Oct 03, 2017 10:51 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Octopus step positions are reusable walks in the light of the natural steps with your own specific parameters and bearings web designing agency Dubai Octopus supports two sorts of step designs. Custom walk organizations and gathering step formats.
Left by Hina Eni on Oct 05, 2017 10:45 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
There is a lot about leaf blowers in the market. They are some of the needed machines during the fall.

Left by Mark Taylor on Oct 05, 2017 11:11 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Accidentally I have come across this site and little bit confused about the subject shared here. I am not familiar with the computing technology and here it describes about the template design in Octopus Deploy. Please make this topic simpler and update it.glass smoking pipes
Left by Ann on Dec 04, 2017 11:48 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Nice post. thanks for sharing..
All pc errors
Left by JOSAM on Dec 27, 2017 11:26 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
improving your improvement workflow is one of the maximum vital things a developer can do. coursework help capable of manipulate your tools fast and professionally lets you spend a while running on real improvement instead of aggressive your tools or doing boring, repetitive things.
Left by Daisy Faith on Jan 05, 2018 7:37 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
When some thing is deployed wrong, the deployment log is your first port of call, and in case you can not believe the element interior that log, you will be in a international of ache. We visit every duration to keep your identification hidden, so choose up your telephone and tell us in case you want someone to Do My Essays For Me UK.
Left by Jennifer Judy on Jan 18, 2018 5:01 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Informative article, here we get all the instructions step by step. This is very much helpful for me to understand more about Effective template design in Octopus Deploy.Thanks for sharing this article and expecting more interesting articles like this.print spooler service not running
Left by riya on Feb 09, 2018 7:51 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Step Templates are viably replicated to ventures utilizing them
Assignment Writing Service that implies in the event that you refresh a stage layout, you'll have to refresh the progression in the undertaking utilizing it for your progressions to have an impact.
Left by Alicia Gill on Feb 26, 2018 10:27 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Here you have provided the complete details regarding the effective step template design. If you are going to write this template design, this blog will definitely an advantage for you. I have gone through it and found that it was very useful for me.dc night tours
Left by Dorrah on Feb 28, 2018 10:59 AM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
Its look slightly complex, i have stuck in between coding when developing online school management software for my software house
Left by Farah Naz on Mar 06, 2018 2:58 PM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
At the point when something is conveyed wrong, the arrangement log is your first port of call, and in the event that you can not trust the component inside that log, you will be in a universal of hurt. Hotline miami letterman Jacket - Hjackets
Left by catrich on Apr 06, 2018 2:18 PM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
There are two reasons why you're probably not going to code considerable contents inside the Octopus IDE itself. Most importantly, you don't get the Intellisense and fruition you get with the Powershell ISE. Besides, there's no sort of a scratchpad for investigating contents in Octopus itself: the main way you can test your code is to make a discharge, pick the progression or steps you need to test, and send it to a situation.Essay writers uk
Left by Eliana Hermione on Apr 26, 2018 1:17 PM

# re: Effective Step template design in Octopus Deploy
Requesting Gravatar...
I generally do not publish in Blogs but your blog forced me to, awesome perform.. stunning bank account pakistan
Left by Billi on May 30, 2018 7:50 AM

Your comment:
 (will show your gravatar)


Copyright © Alex Hildyard | Powered by: GeeksWithBlogs.net