Octopus project broken after delete of channel

Hello,

we delete a channel from one of our deployment processes and unfortunately, the whole project becomes unreachable - we are not even able to open that project.

Could you please help us to make that project available again?

There is an error log:

2022-02-09 19:56:19.7513  17620     24 TRACE  The resource 'Rollout Release version' was not found.
Nevermore.ResourceNotFoundException: The resource 'Rollout Release version' was not found.
   at Octopus.Core.Model.Projects.DeploymentActionCollectionExtensionMethods.GetByIdOrName(IEnumerable`1 actions, String deploymentAction) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Core\Model\Projects\DeploymentActionCollectionExtensionMethods.cs:line 13
   at Octopus.Server.Web.Mapping.DeploymentActionPackageNameMapper.MapToNames(Project project, DeploymentActionPackage deploymentActionPackage) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\DeploymentActionPackageNameMapper.cs:line 56
   at Octopus.Server.Web.Mapping.Mappings.DeploymentSettingsToResourceMappings.<ContributeMaps>b__0_1(DeploymentSettings deploymentSettings, DeploymentSettingsResource resource, IResourceMappingContext ctx, IResourceMapper mapper, AllRoutes routes, ILifetimeScope scope) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\Mappings\DeploymentSettingsToResourceMappings.cs:line 42
   at Octopus.Server.Web.Mapping.ResourceMappingBuilder`2.<>c__DisplayClass10_1.<EnrichResource>b__1(TModel m, TResource r) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\ResourceMappingBuilder.cs:line 101
   at Octopus.Server.Web.Mapping.ActionResourceEnricher`2.EnrichResource(TModel model, TResource resource) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\ActionResourceEnricher.cs:line 17
   at Octopus.Server.Web.Mapping.ResourceMapping`2.<>c__DisplayClass15_0.<AfterMapToResourceInternal>b__0(Func`2 f) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\ResourceMapping.cs:line 96
   at Octopus.Server.Extensibility.HostServices.Infrastructure.EnumerableExtensions.ForEach[T](IEnumerable`1 these, Action`1 action)
   at Octopus.Server.Web.Mapping.ResourceMapper.ModelToResource(Object model, Object resource, Boolean detailed, IResourceMapping resourceMapping) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\ResourceMapper.cs:line 206
   at Octopus.Server.Web.Mapping.ResourceMapper.<>c__DisplayClass4_0.<ConvertTo>b__0(IResourceMapping mapping) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\ResourceMapper.cs:line 45
   at Octopus.Server.Web.Mapping.ResourceMapper.ConvertTo(Object model, Type resourceType, ResourceMapperMode mode) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\ResourceMapper.cs:line 42
   at Octopus.Server.Web.Mapping.ResourceMapper.ConvertTo[TResource](Object model, ResourceMapperMode mode) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Mapping\ResourceMapper.cs:line 33
   at Octopus.Server.Web.Controllers.Projects.GetProjectByIdOrSlugController.GetByIdOrSlug(String id, CancellationToken token) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Controllers\Projects\GetProjectByIdOrSlugController.cs:line 72
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   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, Lazy`1 unitOfWork, ILog log, IActionContextAccessor actionContextAccessor) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\UnitOfWorkMiddleware.cs:line 29
   at Octopus.Server.Web.UnitOfWorkMiddleware.InvokeAsync(HttpContext httpContext, Lazy`1 unitOfWork, ILog log, IActionContextAccessor actionContextAccessor) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\UnitOfWorkMiddleware.cs:line 41
   at Octopus.Server.Web.Middleware.OctopusClientOldVersionWarningMiddleware.InvokeAsync(HttpContext context, IAutomationContext automationContext) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Middleware\OctopusClientOldVersionWarningMiddleware.cs:line 28
   at Octopus.Server.Web.Middleware.RequestLoggerMiddleware.InvokeAsync(HttpContext context) in C:\BuildAgent\work\c42ca9d2b8233f1c\source\Octopus.Server\Web\Middleware\RequestLoggerMiddleware.cs:line 33
   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

Hi @TomasUnverdorben,

Thanks for reaching out! I’ll do my best to assist you here.
It looks like you’re encountering a permutation of this issue: GitHub Issue.

Can you please find out the Projects-Id of the project in question?
You should be able to find this in either a task log of a deployment of the project or the audit log where a project change has taken place.

This issue is usually caused by release versioning rules in the project settings or the channels not lining up with what exists in the project process steps.

If you’re able to get the project ID, you can reset the versioning strategy of the project using the below script; please note the variables entered MUST be correct for the script to work.

$spaceId must be the ID of the space containing the broken project.
$projectGroupName must be a currently existing project group inside the space $spaceId.
$lifecycleName must be a currently existing lifecycle name inside the space $spaceId.
$brokenProjectId must be a valid project ID (This is the project that you cannot open).

# Create Script Variables
$octopusUrl = "https://OctopusURL"
$octopusAPIKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }

# Case Specific Variables | Customise Lifecycle Name and Project Group if necessary.
$spaceId = "Spaces-1"
$newProjectName = "Project_For_Template"
$newProjectDescription = "Project created for version template to fix broken references. Will be deleted after."
$projectGroupName = "Default Project Group"
$lifecycleName = "Default lifecycle"

# BROKEN PROJECT ID
$brokenProjectId = "Projects-XX"

# Get Project Group Id
$projectGroup = (Invoke-RestMethod -Method Get "$octopusURL/api/$($spaceId)/projectgroups/all" -Headers $header) | Where-Object {$_.Name -eq $projectGroupName}

# Get Lifecycle Id
$lifeCycle = (Invoke-RestMethod -Method Get "$octopusURL/api/$($spaceId)/lifecycles/all" -Headers $header) | Where-Object {$_.Name -eq $lifecycleName}

# JSON Payload for template project
$jsonPayload = @{
    Name = $newProjectName
    ProjectGroupId = $projectGroup.Id
    LifeCycleId = $lifeCycle.Id
}

# Create new project
$newProject = Invoke-RestMethod -Method Post -Uri "$octopusURL/api/$($spaceId)/projects" -Body ($jsonPayload | ConvertTo-Json -Depth 10) -Headers $header

# Gather deployment settings template
$depTemplate = Invoke-RestMethod -Method Get -Uri "$octopusURL$($newProject.Links.DeploymentSettings)" -Headers $header

# Copy and modify template to match broken project
$newDepSettings = $depTemplate
$newDepSettings.Id = $newDepSettings.Id.replace($newProject.Id, $brokenProjectId)
$newDepSettings.ProjectId = $newDepSettings.ProjectId.replace($newProject.Id, $brokenProjectId)

# Determine deployment settings URL for broken project
$newUrl = $newProject.Links.DeploymentSettings.replace($newProject.Id, $brokenProjectId)

# Upload newly created default deployment settings to broken project
Invoke-RestMethod -Method Put -Uri "$octopusURL$($newUrl)" -Headers $header -Body ($newDepSettings | ConvertTo-Json -Depth 10)

# Delete Template Project
Invoke-RestMethod -Method Delete -Uri "$octopusURL/api/$($spaceId)/projects/$($newProject.Id)" -Headers $header

Running this script should at least gain you access to the project, if not completely resolve your issue.

Please let me know how it goes or if you run into any issues whilst running this script, and I’ll do my best to help!

Kind Regards,
Adam

1 Like

Works like a charm! Thanks a lot

1 Like

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