Issues icon indicating copy to clipboard operation
Issues copied to clipboard

Trigger may not fire if step set in release versioning doesn't match step set in channel

Open patrick-smergut-octopus opened this issue 1 year ago • 1 comments

Severity

Impacting one customer, potential to impact others

Version

2024.2.4636

Latest Version

None

What happened?

When a trigger fires, there are 2 areas involved that are used to reference a step to get versioning from a package:

  • In the associated channel
  • In the project's release versioning

If these aren't both pointing to the same step, the trigger can fail to fire even when the same package is being deployed in the different steps.

This seems to happen primarily when the steps referenced are restricted to a different environment and/or channel than those specified in the trigger.

Reproduction

Upload a test package to the internal feed with a dev pre-release tag (e.g. TestPackage.1.0.0-dev.zip).

Create a project with the following:

  • Two Deploy a Package steps that deploy the same package, with each step set to only 'Prod' environment or 'Dev' environment, and corresponding Prod channel and Dev channel
  • A Prod channel that uses a prod-only env lifecycle, version rules based on the Deploy a Package only to 'Prod' step, and excludes pre-release tags with ^$
  • A Dev channel that uses a dev-only env lifecycle, version rules based on the 'Deploy a Package' only to 'Dev' step, and pre-release tag matching dev
  • Set the Project's release versioning strategy to use package version from Deploy a Package to Prod step above (note this is a different step than the one used by the Dev channel, but this step references the same package)

image

image

Configure a trigger to create/deploy a release:

  • Set the Dev channel as the channel to create the release in
  • Set the 'Dev' environment as the environment to deploy the release to Use the Deploy a Package only to Dev step Set the channel to the prod-only one

image

Set the trigger to fire, and when it is processed the below error should be presented.

Error and Stacktrace

| == Failed: Process recurring scheduled triggers ==
17:35:20   Fatal    |   Failed to process scheduled triggers [Deploy to dev]
                    | 
                    |   == Warning: Processing Deploy to dev ==
17:35:20   Info     |     Processing trigger [Deploy to dev](~/app#/Spaces-184/projects/Projects-5147/triggers/scheduled/edit/ProjectTriggers-1663)...
17:35:20   Info     |     Creating and deploying a new release for project Break project trigger in the Dev only channel to Development.
17:35:20   Error    |     A scheduled trigger failed while attempting to create and deploy a release
                    |     Object reference not set to an instance of an object.
                    |     System.NullReferenceException: Object reference not set to an instance of an object.
                    |     at Octopus.Server.Communications.Packages.SnapshotCreationFactory`2.SetVersionFromVersioningStrategy(IOctopusQueryExecutor queryExecutor, Project project, Release release, IEnumerable`1 candidateVersioningSteps, VariableCollection variables, IReadOnlyCollection`1 channelsForProject) in ./source/Octopus.Server/Communications/Packages/SnapshotCreationFactory.cs:line 214
                    |     at Octopus.Server.Communications.Packages.SnapshotCreationFactory`2.<>c__DisplayClass16_0.<FillAndCreateSnapshot>b__4(Release r) in ./source/Octopus.Server/Communications/Packages/SnapshotCreationFactory.cs:line 168
                    |     at Octopus.Core.Model.Projects.SnapshotMatchExtensionMethods.<>c__DisplayClass0_0.<<Switch>b__0>d.MoveNext() in ./source/Octopus.Core/Model/Projects/ISnapshot.cs:line 33
                    |     --- End of stack trace from previous location ---
                    |     at Octopus.Core.Model.Projects.SnapshotMatchExtensionMethods.<>c__DisplayClass2_0.<<Switch>b__0>d.MoveNext() in ./source/Octopus.Core/Model/Projects/ISnapshot.cs:line 66
                    |     --- End of stack trace from previous location ---
                    |     at Octopus.Core.Model.Projects.SnapshotMatchExtensionMethods.Switch(ISnapshot snapshot, Func`3 releaseAction, Func`3 runbookSnapshotAction, CancellationToken cancellationToken) in ./source/Octopus.Core/Model/Projects/ISnapshot.cs:line 62
                    |     at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
                    |     at Octopus.Core.Model.Projects.SnapshotMatchExtensionMethods.Switch(ISnapshot snapshot, Action`1 releaseAction, Action`1 runbookSnapshotAction) in ./source/Octopus.Core/Model/Projects/ISnapshot.cs:line 29
                    |     at Octopus.Server.Communications.Packages.SnapshotCreationFactory`2.FillAndCreateSnapshot(IOctopusQueryExecutor queryExecutor, ProjectReference projectReference, IProcess process, TSnapshot snapshot, IOctopusPrincipalInternal octopusPrincipal, Channel releaseChannel, IReadOnlyCollection`1 projectChannels, CancellationToken cancellationToken)
                    |     at Octopus.Server.Communications.Packages.ReleaseCreation.ReleaseCreationFactory.FillAndCreateRelease(IOctopusQueryExecutor queryExecutor, ProjectReference projectReference, Release release, CancellationToken cancellationToken, IOctopusPrincipalInternal octopusPrincipal) in ./source/Octopus.Server/Communications/Packages/ReleaseCreation/ReleaseCreationFactory.cs:line 67
                    |     at Octopus.Server.Orchestration.ServerTasks.ProcessRecurringScheduledDeployments.ScheduledProjectTriggerProcessor.CreateRelease(ProjectReference projectReference, DeploymentSettings settings, Channel channel, ProjectTrigger trigger, CancellationToken cancellationToken) in ./source/Octopus.Server/Orchestration/ServerTasks/ProcessRecurringScheduledDeployments/ScheduledProjectTriggerProcessor.cs:line 469
                    |     at Octopus.Server.Orchestration.ServerTasks.ProcessRecurringScheduledDeployments.ScheduledProjectTriggerProcessor.DeployNewRelease(ProjectTrigger trigger, ITaskLog taskLog, CancellationToken cancellationToken) in ./source/Octopus.Server/Orchestration/ServerTasks/ProcessRecurringScheduledDeployments/ScheduledProjectTriggerProcessor.cs:line 348
                    |     at Octopus.Server.Orchestration.ServerTasks.ProcessRecurringScheduledDeployments.ScheduledProjectTriggerProcessor.SafelyDeployNewRelease(ProjectTrigger trigger, ITaskLog taskLog, CancellationToken cancellationToken) in ./source/Octopus.Server/Orchestration/ServerTasks/ProcessRecurringScheduledDeployments/ScheduledProjectTriggerProcessor.cs:line 308
                    |     Octopus.Server version 2024.2.4636 (2024.2.4636)
17:35:20   Verbose  |     Update the last scheduled time for Deploy to dev to 4/12/2024 5:35:19 PM

More Information

Internal link to repro

First reported here [internal]

Similar to https://github.com/OctopusDeploy/Issues/issues/8736

Workaround

Use the same step in the Project Release Version configuration as the one used in the channel version rule, and make sure the step can run for that channel. For example:

  • Trigger configuration - Create release in: Dev only, deploy to Environment: Dev
  • Dev only channel version rule - Pre-release tag: dev, Referenced Step: Deploy my custom script
  • Deploy my custom script step - Channel: Dev only, Environment: Dev

patrick-smergut-octopus avatar Apr 12 '24 20:04 patrick-smergut-octopus

The issue arises when Octopus can not determine the version of an automatically created release. We consider this a configuration issue and will not issue a patch. When a project is configured to "Use the version number from an included package", the step must apply to all channels.

tothegills avatar Apr 15 '24 22:04 tothegills