Skip to content

fix: Handle scenario where environment name query field isn't respected - #771

Merged
APErebus merged 5 commits into
mainfrom
ap/tweak-getting-an-environment
Oct 19, 2026
Merged

APErebus merged 5 commits into
mainfrom
ap/tweak-getting-an-environment

Conversation

@APErebus

Copy link
Copy Markdown
Contributor

Older versions of Octopus Server (read before 2026.1) did not support the Name exact match parameter when querying environments.

This was discovered when testing the updated TeamCity plugin using the new release promote command.

To fix this, when retrieving the environment, we try first by Id, then Name. If that returns multiple results, it likely means the name query param is not being respected and it won't be applying the filter, so will be returning more data than expected.

In this case, we just do the filtering ourselves in code

@github-actions github-actions Bot added the fix label Oct 19, 2026
@APErebus APErebus changed the title fix: Try get environment by partial name when promoting fix: Handle scenario where environment name query field isn't respected Oct 19, 2026
@APErebus
APErebus requested a review from liam-mackie October 19, 2026 06:11

@liam-mackie liam-mackie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that it's required, but the code looks good. I would prefer an additional safety check in ensuring the text passed in by the user matches either the name or the ID before returning, but otherwise LGTM!

Comment thread pkg/executor/release.go Outdated
Comment on lines +374 to +376
if len(envResponse.Items) == 1 {
return envResponse.Items[0], nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case, could we add an additional check here to ensure the ID of the space matches the ID passed in? I just don't want a case of us using the wrong environment if someone only has permissions to access one of them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good call. I've also changed this api call to take: 1

@APErebus

Copy link
Copy Markdown
Contributor Author

I don't like that it's required, but the code looks good. I would prefer an additional safety check in ensuring the text passed in by the user matches either the name or the ID before returning, but otherwise LGTM!

I'll take a look tomorrow morning. This was pretty quick and dirty

Comment thread pkg/executor/release.go
switch {
case len(envResponse.Items) == 0:
return nil, fmt.Errorf("environment not found")
case len(envResponse.Items) == 1 && strings.EqualFold(envResponse.Items[0].Name, nameOrID):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these checks are case-insensitive to match Octopus Server's case-insensitive DB query

Comment thread pkg/executor/release.go
}

// double check the ID and return if true
if len(envResponse.Items) == 1 && envResponse.Items[0].ID == nameOrID {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is case sensitive because ID's should be case-sensitive

@APErebus
APErebus merged commit 93425bb into main Oct 19, 2026
4 checks passed
@APErebus
APErebus deleted the ap/tweak-getting-an-environment branch October 19, 2026 22:16
APErebus pushed a commit that referenced this pull request Oct 19, 2026
##
[2.31.0](v2.30.1...v2.31.0)
(2026-10-19)


### Features

* Obey Octopus Server rate limits
([#757](#757))
([ca31c83](ca31c83))


### Bug Fixes

* Handle scenario where environment name query field isn't respected
([#771](#771))
([93425bb](93425bb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: team-integrations-fnm-bot <integrationsfnmbot@octopus.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants