Unable to publish runbook

Hi,
We recently upgraded Octpous to 2020.3.2. I copied a project and created a new one which includes process, Variables, runbooks and triggers

I deleted all the process step and left variables, runbooks and triggers. When i check trigger it syas runbook is not published. I created a new runbook and modified existing however didnt get any option to publish the same.

I executed the same and post execution we got an option to publish. I updated a varibale and earlier used to get an option in runbook to publish however now without running the same we are not getting publish option. this way we cannot put trigger

This behaviour is only observed now earlier version was giving option after every modification to publish even without running the same

Hi @aprasun,

Thanks for reaching out.

This is actually by design. It’s designed this way as a safety measure so that you can’t publish a runbook without having manually tested it once. I know that’s probably not the answer you were hoping for, but please let me know if you have any other questions or concerns.

Thanks,
Jeremy

@jeremy.miller. understood the design description however those runbooks are moved created by copying entire project which copied triggers and runbooks

Is their any easier way to move runbooks and triggers between projects

Hi @aprasun,

Could you please take a look at this issue and see if it reflects what you’re seeing?

It looks pretty similar to what you’re describing.

Thanks,
Jeremy

@jeremy.miller exactly the same. There is no publish option with latest version 2020.3.3
With earlier version even if we modify a variable we get an option to publish which we are not even getting now.
So as per the issue is there any fix planned in coming days? We have almost 100 runbooks and its bit cumbersome to run and then publish even in case of variable change

Hi @aprasun,

Unfortunately, I’m not sure what the timeline on this fix is.

You may be able to build an API script to automate it.

As a test could you try:

  1. find the runbook ID via YOUROCTOURL/api/runbooks/all
  2. go to YOUROCTOURL/api/YOURSPACEID/runbookProcesses/RunbookProcess-YOURRUNBOOKID/runbookSnapshotTemplate and get the NextNameIncrement like “Snapshot K5LUD7E”
  3. Get the packages information from that section
  4. Run a POST Invoke-RestMethod -Method "POST" -Uri "$OctopusUrl/api/SPACEID/runbookSnapshots?publish=true" -Body $jsonBody -Headers @{"X-Octopus-ApiKey"=$ApiKey} Where $jsonbody is

Example:

$jsonBody = @"
    {"ProjectId":"PROJECTID","RunbookId":"RUNBOOKID","Notes":null,"Name":"SNAPSHOT STRING FROM STEP 2","SelectedPackages":PACKAGES FROM STEP 3}
    "@

For example mine looked like this:

$jsonBody = @"
{"ProjectId":"Projects-242","RunbookId":"Runbooks-101","Notes":null,"Name":"Snapshot PWPKYVK","SelectedPackages":[{"ActionName":"Test","Version":"1.0.0","PackageReferenceName":"Octopus.Client"}]}
"@

I tested this on my cloud instance, 2020.3.2, and it appears to have published the runbook but it doesnt show it until I try to run it that it is running a published version of the runbook.

If the above test works for your use-case, you could create an array of the runbooks from the projects you’ve cloned, and then run through the above logic on each runbook to publish them all automatically.

I’ve created some example code here that works, but is not fully automated:

$OctopusUrl = ""
$ApiKey = ""
$clonedProject = "Projects-242"
$runbooks = Invoke-RestMethod -Method "GET" -Uri "$OctopusUrl/api/runbooks/all" -Headers @{"X-Octopus-ApiKey"=$ApiKey}
$runbookIds = @()

#create array of runbooks in the project that need updated
foreach ($item in $runbooks){
if ($item.ProjectId -eq $clonedProject){
    $runbookIds += $item.Id   
}
}

$packages = Invoke-RestMethod -Method "GET" -Uri "$OctopusUrl/api/Spaces-1/packages" -Headers @{"X-Octopus-ApiKey"=$ApiKey}
$runbooktemplate = Invoke-RestMethod -Method "GET" -Uri "$OctopusUrl/api/Spaces-1/runbookProcesses/RunbookProcess-$($runbookIds[0])/runbookSnapshotTemplate" -Headers @{"X-Octopus-ApiKey"=$ApiKey}

#match latest package version
foreach ($package in $packages.Items){
if ($package.PackageId -eq $runbooktemplate.Packages.PackageReferenceName){
$packageversion = $package.version
}
}
#create object to later put as json (would need to change the runbookId if you are iterating through the array. I just wanted to test 1 runbook
$obj = New-Object -Type PSObject -Property @{
'ProjectId'   = $($clonedProject)
'RunbookId' = $($runbookIds[0])
'Notes' = ''
'Name' = $($runbooktemplate.NextNameIncrement)
'SelectedPackages' = @()
}
#LOGIC NEEDED FOR MULTIPLE STEPS+MULTIPLE PACKAGES
#Iterate through each step in runbook template
#iterate through each package in each step in runbook template
#add each package to selected packages

$packages = @{
ActionName = "$($runbooktemplate.Packages.ActionName)"
version = "$($packageversion)"
PackageReferenceName = "$($runbooktemplate.Packages.PackageReferenceName)"
}

$obj.SelectedPackages += $packages

$jsonbody = ($obj | ConvertTo-Json -depth 10)
#write-host $jsonBody
Invoke-RestMethod -Method "POST" -Uri "$OctopusUrl/api/Spaces-1/runbookSnapshots?publish=true" -Body $jsonBody -Headers @{"X-Octopus-ApiKey"=$ApiKey}

This logic works for one runbook with 1 package in it, using the latest package version of that package. More logic would need to be implemented to have multiple packages+not the latest version of the package. You could hit F12 in your browser and follow the API calls to see what kind of work would need to be done to implement that if the logic is necessary for that.

For now, I would subscribe to that github issue and it will be updated as its fixed.

As always, if you use my script examples above, please use in a test environment first to ensure you are getting the results you want. These are not guaranteed to work in your scenario.

Please let me know if you have any other questions or concerns.

Thanks,
Jeremy

Hi @jeremy.miller
Thanks for the rest method. This seems to be working. However a fix in future can make this lengthy process a bit easier.

Also i raised one more issue, if you can help me with that as well. Thanks for your kind help
https://help.octopus.com/t/ssl-thumbprint-update-not-reflecting-in-ssl-change/25518/5

Hi @aprasun,

You’re very welcome. Were you able to adapt it to iterate through all your runbooks and take into account all the packages? I was worried it would be more work than just manually going and doing the runs+publish.

The fix is definitely in the works for the publish button to come back, I’m just not sure how long it will be.

It looks like Dane gave you a response over on that thread so I’ll leave that with him for now. He is in Australia so his responses will be in that timeframe.

By which method are you cloning projects? I’m not sure that it’s by design to have the runbooks already published on a cloned project, but that button should be there. A complex API call that takes into count all your use cases for runbooks+packages to re-publish all of them might be worth the effort if you clone projects often.

Let me know what you think.

Thanks,
Jeremy

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.