Trying to Publish a Snapshot with ZIP packages

Hi,

I am experiencing an issue where I am trying to publish a snapshot with packages (Zipped files with .exe) via API and it is not working due to PackageReferenceName being null I suppose. Below is the error from Server Diagnostics:

Unhandled error on request: POST http://<serverIP>:<serverPort>/api/Spaces-1/runbookSnapshots?publish=true 80000d69-0000-f700-b63f-84710c7967bb by Kraken : Value cannot be null. (Parameter 'key') System.ArgumentNullException: Value cannot be null. (Parameter 'key')

at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at Octopus.Server.Web.Api.Rules.SnapshotPackageVersionSetter.EnsureCorrectStepNameAndVersionIsSpecifiedForEveryPackage(IReadOnlyList1 packageSteps, IEnumerable1 selectedPackages, ISnapshot snapshot, IReadOnlyList1 steps) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Api\Rules\SnapshotPackageVersionSetter.cs:line 30
at Octopus.Server.Web.Api.Rules.RunbookSnapshotPackageVersionsMustBeSpecifiedRule.AfterMapBeforeStore(RunbookSnapshot model, RunbookSnapshotResource resource, ISpecialRuleContext context) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Api\Rules\RunbookSnapshotPackageVersionsMustBeSpecifiedRule.cs:line 28
at Octopus.Server.Web.Infrastructure.Api.Responder1.ExecuteRegisteredRules[TRule](Action2 ruleCallback, IOctopusRelationalTransaction transaction) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Infrastructure\Api\Responder.cs:line 61
at Octopus.Server.Web.Infrastructure.Api.CustomCreateResponder3.ExecuteRegistered() in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Infrastructure\Api\CustomCreateResponder.cs:line 97 at Octopus.Server.Web.Infrastructure.Api.Responder1.Respond(TDescriptor options, NancyContext context) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Infrastructure\Api\Responder.cs:line 46
at Octopus.Server.Web.Infrastructure.OctopusNancyModule.<>c__DisplayClass14_0.<get_Routes>b__1(Object o, CancellationToken x) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Infrastructure\OctopusNancyModule.cs:line 82
at Nancy.Routing.Route1.Invoke(DynamicDictionary parameters, CancellationToken cancellationToken) at Nancy.Routing.DefaultRouteInvoker.Invoke(Route route, CancellationToken cancellationToken, DynamicDictionary parameters, NancyContext context) at Nancy.Routing.DefaultRequestDispatcher.Dispatch(NancyContext context, CancellationToken cancellationToken) at Nancy.NancyEngine.InvokeRequestLifeCycle(NancyContext context, CancellationToken cancellationToken, IPipelines pipelines) at Octopus.NancyOwin.NancyMiddleware.RequestComplete(NancyContext context, IDictionary2 environment) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Owin\NancyMiddleware.cs:line 172
at Octopus.NancyOwin.NancyMiddleware.<>c__DisplayClass3_0.<b__1>d.MoveNext() in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Owin\NancyMiddleware.cs:line 108
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Owin.WebSocketAcceptAdapter.<>c__DisplayClass6_0.<b__0>d.MoveNext()
— End of stack trace from previous location where exception was thrown —
at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.HttpOverrides.HttpMethodOverrideMiddleware.Invoke(HttpContext context)
at Octopus.Server.Web.UnitOfWorkMiddleware.InvokeAsync(HttpContext httpContext, Lazy1 unitOfWork, ILog log, IActionContextAccessor actionContextAccessor) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\UnitOfWorkMiddleware.cs:line 42 at Octopus.Server.Web.UnitOfWorkMiddleware.InvokeAsync(HttpContext httpContext, Lazy1 unitOfWork, ILog log, IActionContextAccessor actionContextAccessor) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\UnitOfWorkMiddleware.cs:line 42
at Octopus.Server.Web.Middleware.OctopusClientOldVersionWarningMiddleware.InvokeAsync(HttpContext context, IAutomationContext automationContext) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Middleware\OctopusClientOldVersionWarningMiddleware.cs:line 38
at Octopus.Server.Web.Middleware.RequestLoggerMiddleware.InvokeAsync(HttpContext context) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Middleware\RequestLoggerMiddleware.cs:line 42
at Octopus.Server.Web.Middleware.ErrorHandlingMiddleware.InvokeAsync(HttpContext context, CorrelationId correlationId) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Middleware\ErrorHandlingMiddleware.cs:line 82

and the body looks something like this :

{
“ProjectId”: “Projects-1”,
“Notes”: null,
“Name”: “Snapshot 6PE7KVF”,
“RunbookId”: “Runbooks-29”,
“SelectedPackages”: [
{
“Id”: “Runbooks-29”,
“Name”: “Host Preparation”,
“Description”: “”,
“RunbookProcessId”: “RunbookProcess-Runbooks-29”,
“PublishedRunbookSnapshotId”: null,
“ProjectId”: “Projects-1”,
“SpaceId”: “Spaces-1”,
“MultiTenancyMode”: “Untenanted”,
“ConnectivityPolicy”: {
“SkipMachineBehavior”: “SkipUnavailableMachines”,
“TargetRoles”: [
“Role1”,
“Role2”,
“Role3”,
“Role4”
],
“AllowDeploymentsToNoTargets”: true,
“ExcludeUnhealthyTargets”: false
},
“EnvironmentScope”: “Specified”,
“Environments”: [
“Environments-361”
],
“DefaultGuidedFailureMode”: “EnvironmentDefault”,
“RunRetentionPolicy”: {
“QuantityToKeep”: 100,
“ShouldKeepForever”: false
},
“Links”: {
“Self”: “/api/Spaces-1/runbooks/Runbooks-29”,
“Project”: “/api/Spaces-1/projects/Projects-1”,
“Template”: “/api/Spaces-1/runbooks{/id}{?skip,take,ids,partialName,clone,projectIds}”,
“RunbookSnapshotTemplate”: “/api/Spaces-1/runbooks/Runbooks-29/runbookSnapshotTemplate”,
“RunbookRunTemplate”: “/api/Spaces-1/runbooks/Runbooks-29/runbookRunTemplate”,
“RunbookRunPreview”: “/api/Spaces-1/runbooks/Runbooks-29/runbookRuns/preview/”,
“RunbookRunTenantPreview”: “/api/Spaces-1/runbooks/Runbooks-29/runbookRuns/preview//”,
“CreateRunbookRun”: “/api/Spaces-1/runbooks/Runbooks-29/run”,
“RunbookProcesses”: “/api/Spaces-1/runbookProcesses/RunbookProcess-Runbooks-29”,
“Progression”: “/api/Spaces-1/progression/runbooks/Runbooks-29{?aggregate}”,
“TaskRunDashboardItemsTemplate”: “/api/Spaces-1/progression/runbooks/taskRuns{?skip,take,ids,projectIds,
runbookIds,environmentIds,tenantIds,taskIds}”,
“RunbookSnapshots”: "/api/Spaces-1/runbooks/Runbooks-29/runbookSnapshots{/name}{?skip,take,searchByName}
",
“RunbookEnvironments”: “/api/Spaces-1/runbooks/Runbooks-29/environments”
}
},
{
“PackageReferenceName”: “”,
“Version”: “1”,
“ActionName”: “Transfer a Package”
}
]
}

Appreciate some help on how to generate the PackageReferenceName since it is a zip file or at least how to publish without that particular value via API.

Thanks!

Andrew

Also, I am posting this in a Runbook not in a Deployment Process …

I am trying to publish a runbooks snapshot before triggering it via API as I am adding variables right before the triggering and I want updated values. now I think I was working on the wrong track and seeing a lot of information about the deployment process and now how to actually set and trigger the runbook. I remember converting the code from the deployment process to the runbook process but now I am stuck on what is needed for this to be published as clearly I am missing some important value. I am also not sure about the variable snapshot, do I have to publish it as well before I publish the runbook? can I publish/update the variable set only instead ?

Thanks again and Sorry for the confusion :sweat_smile:

Andrew

Hi Andrew,

Thanks for getting in touch!

If you have a Published Runbook snapshot and only want to refresh the variables, then the easiest option would be to run the update variables REST API call.
e.g.

https://<serverURL>/api/<spaceID>/runbookSnapshots/RunbookSnapshots-866/snapshot-variables

If there are other changes being made that require a new snapshot/Publish to occur, then our sample script (OctopusDeploy-Api/CreateAndPublishRunbookSnapshot.ps1 at master · OctopusDeploy/OctopusDeploy-Api · GitHub) may be a good starting point.

Regards,
Paul

Thanks @paul.calvert I think that is what I needed will test and let you know how it goes :slight_smile:

Andrew

1 Like

Thanks Again @paul.calvert , Worked like a Charm. I was giving the wrong -Body from my end for the packages etc… but with the simple line to update variables it resolved all my issues and much less code.

Have a nice day!

Andrew

1 Like

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