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:
- find the runbook ID via YOUROCTOURL/api/runbooks/all
- go to YOUROCTOURL/api/YOURSPACEID/runbookProcesses/RunbookProcess-YOURRUNBOOKID/runbookSnapshotTemplate and get the NextNameIncrement like “Snapshot K5LUD7E”
- Get the packages information from that section
- 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