I’m searching already very long for a solution but I couldn’t find one and very much hope the community can help me.
We are deploying our DB changes with a tool called Liquibase, we have it installed on one of the Tentacles and run it whenever we deploy and it works good. For a every change we have a script and also a rollback script.
We also have a (unpublished) runbook which we can run to deploy the DB scripts to an “Snapshot” DB. This snapshot is basically a copy of PROD we get every night. The Runbook is applying the scripts and is then also running the rollback scripts. We need to do that so that we can be sure the scripts and the rollbacks work with production data.
The Runbook is unpublished, we always choose the newest master package when we run it.
We would like to run these runbook nightly, so I thought I can just create a trigger. But a trigger requires a runbook to be published. When a runbook is published a Snapshot with the chossen package version is created and always the runbook is executed, it uses the choosen package version when it was published.
My questions: How can I tell the runbook to dynamically choose the (newest) package (ideally newest package containing the word “master”)?
If this is not possible, can I use the Octopus API to run a unpublished runbook and and always choose the newest (“master”) package? I couldn’t find a ways to search packages and then set them when executing a runbook via API.
Or do you see an easier way to achieve this?
Firstly, let me welcome you to the Octopus Community, it is great to see you here.
Thank you for reaching out with your questions surrounding Runbooks.
As you may have found out, when it comes to Runbooks triggers, “only published snapshots can be used to create a scheduled runbook trigger, draft snapshots cannot be used to create a scheduled trigger” which is mentioned here.
Currently (at the time of writing this) Octopus will only use the package that is referenced as part of the steps when you “Publish” a Runbook and would select the package at the point it was published.
However, saying this, we do have a sample script that can “Update Runbooks to The Latest Package” that can be found within our samples.
This script is a sample, but it is leveraging the REST API so it may help get you to where you need to be. You can look to use this to update your Runbook in question.
Without fully understanding your entire process, it may be worthwhile having another “Published” Runbook that replicates your desired end result with your “unpublished” version.
You could also use another scheduled runbook to run your “update Runbook to latest package” to run just before you come to run your other Runbook.
While it would be technically possible, you could use the REST API to select a different version (the latest) of the package and create a new snapshot each time, but crucially just not publish it. The only reason I can think of to do this if you wanted to test the runbook first, and have a “known good” package version in the published one. But this wouldn’t help if you needed to schedule your Runbook, due to the limitations of the Runbook feature within Octopus.
I hope this helps get you where you need to be.
thx for your fast and sorry for my late response - I wasn’t able to log in and then had other things to do.
Yes I know I can only create trigger with a published runbook, but as I wrote, I need to use always another package when I run it. Basically the package (newest?) the runbook shows when I run it would be perfect.
So if I understood I could write and publish an “UpdateAndRunExistingRunbook” Runbook which uses the rest API to choose a package and start my already existing (unpublished) runbook.
Sounds promising, I got more important tasks right now but I will come back to you as soon as I will try it and give you feedback.
I was kind of hoping in the runbook config, in the “Reference a Package” dialog, I could just set some variable which tells the runbook to take the newest package
Thx a lot!
Yes you could look to use the REST API to help achieve this.
I hope you get on well, let me know if you encounter any issues.
All the best,