Scheduling code deployment with Bitbucket

Having a deployment pipeline is an awesome thing, it eliminates the mundane task of deploying changes. Really let’s face it, if a task is boring or mundane, then there’s likely a chance where a mistake could happen. Sometime though there’s a need to re-deploy, or at least deploy code at a certain time, and that’s where an overlooked feature in Bitbucket pipeline comes in which is simply called Schedules.

Schedule button

You’ll find this cool button at the top of the pipelines screen.

You might be wondering how this feature could be useful? Well if you read my post on Automated code deployment with Bitbucket and Docker, then you’ll know that this blog is generated using Hugo, and one of the features that hugo allows for is to only generate pages, which are available at that time.

For instance this post was committed to the master branch on 2018-03-12, but shouldn’t show until 2018-03-15. If Hugo runs on the 12th then this page is not generated, and it shouldn’t be at that time. If you wanted to on the 15th deploy this page then you would typically go into Bitbucket and then manually re-run the pipeline - not too bad, but we really don’t need to do that with the Schedules feature.

With Schedules you can simply run the pipeline at a scheduled time, with hourly or weekly, which allows you to have a deployment on an incremental timing. For the Camping Coder blog, we release on Tuesdays and Thursdays typically, so we simply schedule those times and boom the Hugo site can deploy on a schedule.

From there you can click on the Schedule button and see everything that scheduled.


Note: There’s a documented bug in pipelines where the day does not always reflect the day you selected. Bitbucket has it in there queue and I’m sure that they will have a fix for it soon. Either way the schedule runs when you select, so it’s merely a graphical issue.

Example: The schedule days are Tuesdays and Thursdays, but the schedules reflect a day earlier.

Wrapping up

Bitbucket Piplines is always innovating and surprising me with what they have to offer. A lot of the time as developers we focus on the tools which we are building and not how to make the tools we use more efficient. Pipelines is a great example on how to use a tool which you are already in and using to do more with less manual effort.

Always follow the manufacturers instructions, this write up is simply the way that I do it, and it may or may not be the right way. Use your common sense when applying products to or altering your stuff and always wear the appropriate safety gear.