Skip to content

🐛 QD-16308 Report "undefined" for a plain docker run and pass QODANA_ENV to the container - #1144

Open
Jakub Andrzejewski (bonepl) wants to merge 1 commit into
mainfrom
andrzejewski/QD-16308
Open

Jakub Andrzejewski (bonepl) wants to merge 1 commit into
mainfrom
andrzejewski/QD-16308

Conversation

@bonepl

Copy link
Copy Markdown
Collaborator

Description

Two changes in qdenv.ExtractQodanaEnvironment (internal/platform/qdenv/qdenv.go):

  • If the CLI runs inside a Qodana image (QODANA_DOCKER is set) and finds no CI, Space or Bitbucket, it does not set QODANA_ENV. The IDE then reports system=undefined to FUS instead of cli.
  • A non-empty QODANA_ENV from the process env is now copied with setEnvironmentFunc, the same way as QODANA_BRANCH and QODANA_REVISION. In docker mode, the value now gets to the container.

Order of precedence for QODANA_ENV: --env, then the process env, then the computed value (<ci>:<ver> or cli:<ver>). Native mode does not change, because SetEnv does not overwrite a non-empty variable.

Related Issue

https://youtrack.jetbrains.com/issue/QD-16308

Motivation and Context

  • A plain docker run jetbrains/qodana-* starts the bundled CLI, which goes through the native path and always set cli:<ver>. Because of this, FUS never got undefined, also with -e QODANA_ENV=.
  • The Gradle and Maven plugins set QODANA_ENV=gradle/maven only in the process env of the CLI. By default they run in docker mode, and getDockerOptions passes only c.Env() to the container. Their value was lost, so FUS showed cli or the CI name.
Scenario Before After
Plain docker run, QODANA_ENV not set or empty cli undefined
qodana scan inside a Qodana image, no CI detected cli undefined
qodana scan on the host (native or docker mode) cli cli
Detected CI, also with the Qodana image as the job image <ci> <ci>
Gradle/Maven plugin, docker mode cli or <ci> gradle/maven
--env QODANA_ENV=... (TeamCity plugin) value from --env value from --env
docker run -e QODANA_ENV=... user value user value

Known behavior changes:

  • The Gradle/Maven plugin on a detected CI in docker mode now reports gradle/maven instead of the CI name. Native mode already works this way.
  • A QODANA_ENV exported in the shell now gets to the container in docker mode too.
  • The undefined value appears only in images with this CLI version. Older images still report cli.

The linter part (bitbucket and maven as known systems, FUS group version 18) is in a separate IntelliJ change.

How Has This Been Tested

  • internal/core/corescan/env_test.go, Test_ExtractEnvironmentVariables, new cases:
    • Plain docker run and Plain docker run with empty QODANA_ENV expect an empty QODANA_ENV.
    • BitBucket Pipelines in Qodana image expects bitbucket:<ver>, so a detected CI still wins inside the image.
  • New test Test_ExtractQodanaEnvironment_PassesOsQodanaEnvToContainer: the process env has QODANA_ENV=gradle and Context{} is empty. The test expects gradle in c.Env().
  • The new tests failed before the fix (cli:dev).
  • go test ./internal/platform/qdenv/ ./internal/core/... passes. gofmt -l reports no files.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My commit messages are styled with gitmoji
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@bonepl
Jakub Andrzejewski (bonepl) requested a review from a team as a code owner November 13, 2026 13:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T13:35:21.783367Z 947d494 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Qodana for Go

127 new problems were found

Inspection name Severity Problems
Vulnerable declared dependency 🔴 Failure 2
Check GO source code coverage 🔶 Warning 67
Unhandled error 🔶 Warning 13
Interprocedural potential nil dereference 🔶 Warning 10
Deprecated element 🔶 Warning 4
Imported package name as a name identifier 🔶 Warning 3
Vulnerable declared dependency 🔶 Warning 2
Reserved word used as name 🔶 Warning 1
Potential resource leak 🔶 Warning 1
Missing 'case' statements for 'iota' consts in 'switch' 🔶 Warning 1
Unsorted imports ◽️ Notice 9
Name starts with a package name ◽️ Notice 8
Empty slice declared using a literal ◽️ Notice 3
Vulnerable declared dependency ◽️ Notice 1
Redundant type conversion ◽️ Notice 1
Comment of exported element starts with the incorrect name ◽️ Notice 1
@@ Code coverage @@
+ 65% total lines covered
10636 lines analyzed, 6985 lines covered
# Calculated according to the filters of your coverage tool

☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant