Skip to content

feat: support JFROG_CLI_URL/ACCESS_TOKEN/USER/PASSWORD env fallbacks (#3490)#3531

Open
mvanhorn wants to merge 1 commit into
jfrog:masterfrom
mvanhorn:feat/3490-env-url-access-token
Open

feat: support JFROG_CLI_URL/ACCESS_TOKEN/USER/PASSWORD env fallbacks (#3490)#3531
mvanhorn wants to merge 1 commit into
jfrog:masterfrom
mvanhorn:feat/3490-env-url-access-token

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented Jun 3, 2026

Summary

Adds environment-variable fallbacks for the core connection details in CreateServerDetailsFromFlags:

  • JFROG_CLI_URL -> --url
  • JFROG_CLI_ACCESS_TOKEN -> --access-token
  • JFROG_CLI_USER -> --user
  • JFROG_CLI_PASSWORD -> --password

A flag value, when supplied, always wins over the corresponding environment variable; the environment variable is used only when the flag (and, for secrets, the --*-stdin path) is empty. When no flag and no env var are set, behavior is unchanged. This mirrors the existing JFROG_CLI_SERVER_ID env fallback that already lives in this same function.

The new variables are documented in docs/common/env.go and registered in GetGlobalEnvVars() so they appear in jf options/help output.

Why this matters

Issue #3490 asks for an env-only path to supply connection details so that pipelines and Docker-based CI can avoid repeating --url/--access-token on every jf invocation (and avoid putting credentials on the command line). The repo already has the exact precedent for this: ServerId falls back to os.Getenv(coreutils.ServerID) (JFROG_CLI_SERVER_ID) inside CreateServerDetailsFromFlags. This change extends that established pattern to the remaining connection fields, keeping the implementation small and consistent.

Behavior notes (intentional, for parity with the flags):

  • JFROG_CLI_URL is treated exactly like --url: per-service URLs (Artifactory/Xray/Distribution) are derived from it by the existing domain switch in createServerDetailsFromFlags, so setting it to a platform base behaves identically to passing --url. No /artifactory auto-append is added.
  • Like the flags today, supplying credentials via these env vars triggers the existing "credentials passed as options" path in CreateServerDetailsWithConfigOffer (credentialsChanged), i.e. command-supplied details and stored server config remain mutually exclusive. This is the same exclusivity already enforced for --access-token/--user/--password.

Testing

  • Added TestCreateServerDetailsFromFlagsEnvFallback in utils/cliutils/utils_test.go, a table-driven test covering: env fallback for url/user/password/access-token, flag-wins-over-env precedence, trailing-slash handling on the URL, and the no-flag/no-env case (empty fields, no regression).
  • gofmt -l clean on all changed files.
  • go vet ./utils/... clean.
  • go build ./... succeeds.
  • go test ./utils/cliutils/... passes (including the new test).

Fixes #3490

AI was used for assistance.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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.

Use environment variables as substitution for passing in --url and --access-token

1 participant