Use Go with JFrog CLI
Run Go commands with Artifactory integration, including configuration, builds, and publishing.
This topic covers the following tasks:
- Configure Go for Artifactory (
jf go-config) - Run Go commands (
jf go) - Publish Go modules (
jf go-publish)
When to Use
Use jf go if your Go project uses Go modules (go.mod) and you want dependencies resolved from Artifactory. The CLI wraps go build, go get, and other Go commands while setting GOPROXY to point at your Artifactory Go repository.
Prerequisites
- Go must be installed (Go 1.16+ recommended for module support). Verify with
go version. - A Go module must exist in the current directory (
go.mod). Initialize one with:For example:go mod init <module-path>go mod init github.com/my-org/my-app - JFrog CLI server configured. See
jf config add— note the server ID, as it is required byjf go-config. - Authentication: A valid Artifactory access token is required. If your token is a reference token (non-JWT), the CLI will emit a
[Warn]about it — Go builds still succeed, but fetching modules from Artifactory withjf go getmay fail with401. Re-runjf config addwith a username if you encounter auth errors. - Run
jf go-configin the project directory before the first build.
Configuration: jf go-config
jf go-configGenerate Go build configuration for dependency resolution and deployment. Run this once per project before your first build.
To configure Go for Artifactory:
- From your Go module directory, run
jf go-configwith resolve and deploy server IDs and repository keys (see Non-Interactive Configuration with Flags). - Confirm
.jfrog/projects/go.yamlexists and matches your settings (see How to Verify).
Synopsis
jf go-config [options]
Aliases: goc
Configuration Options
| Flag | Default | Description |
|---|---|---|
--global | false | Set to true for global configuration (all projects). Specific projects can override. |
--repo-deploy | — | Repository for artifacts deployment |
--repo-resolve | — | Repository for dependencies resolution |
--server-id-deploy | — | Artifactory server ID for deployment. Configure with jf config add. |
--server-id-resolve | — | Artifactory server ID for resolution. Configure with jf config add. |
Configuration Examples
View Help
jf go-config --helpNon-Interactive Configuration with Flags
jf go-config --server-id-resolve=<server-id> --repo-resolve=<repo-name> --server-id-deploy=<server-id> --repo-deploy=<repo-name>Where:
- <server-id>: The server ID configured using
jf config add - <repo-name>: The name of the repository in Artifactory
For example:
jf go-config --server-id-resolve=my-server --repo-resolve=go-virtual --server-id-deploy=my-server --repo-deploy=go-localWhy Run Config First?
You must run jf go-config before jf go or jf go-publish. The config tells the CLI which Artifactory Go repositories to use, setting GOPROXY automatically during builds. Without it, jf go does not know where to fetch or publish modules.
Shortcut
: In CI/CD, pass all flags non-interactively so the config step is fully automated and reproducible.
Configuration Notes
- Run once per project: Configuration persists in
.jfrog/projects/go.yaml. - Resolution and deployment: Use
--repo-resolvefor fetching modules and--repo-deployfor publishing. - GOPROXY override: The CLI temporarily sets
GOPROXYduring execution, overriding any system setting.
Expected Output
$ jf go-config --server-id-resolve=my-server --repo-resolve=go-virtual --server-id-deploy=my-server --repo-deploy=go-local
[Info] go build config successfully created.
How to Verify
After running, confirm the configuration exists:
cat .jfrog/projects/go.yamlThe file should contain:
version: 1
type: go
resolver:
repo: <repo-resolve>
serverId: <server-id-resolve>
deployer:
repo: <repo-deploy>
serverId: <server-id-deploy>Where the repo and serverId values match what you passed to jf go-config.
Build: jf go
jf goRun Go commands with Artifactory integration and optional build-info collection.
To run Go commands with Artifactory integration:
- Run
jf go-configin the module directory if you have not already (see Configuration). - From the module root, run
jf gowith the Go subcommand and arguments, adding--build-nameand--build-numberwhen you want build-info (see Build Examples).
Synopsis
jf go <go-arguments> [options]
Aliases: none
Arguments
| Argument | Required | Description |
|---|---|---|
<go-arguments> | Yes | Arguments and options for the Go command (for example, build, get, mod) |
Build Options
| Flag | Default | Description |
|---|---|---|
--build-name | — | Build name for build-info. Requires --build-number. |
--build-number | — | Build number for build-info. Requires --build-name. |
--module | — | Optional module name for build-info. Requires --build-name and --build-number. |
--no-fallback | false | When true, packages missing in Artifactory will not be downloaded from VCS. Defaults to false, meaning VCS fallback is allowed. Pass --no-fallback or --no-fallback=true to enforce Artifactory-only resolution. |
--project | — | JFrog Artifactory project key |
Build Examples
Note
Run these commands from the root of your Go module directory (where your
go.modfile lives), and only after runningjf go-configin that directory.
View Help
jf go --helpRun a Go Build
jf go build ./...On success, the command exits without error. Check the exit code to confirm (echo $? should return 0).
Run Go with Build-Info Collection
jf go build ./... --build-name=<build-name> --build-number=<build-number>Where:
<build-name>is a name for the build (for example,my-go-app)<build-number>is a number or identifier for the build run (for example,1)
For example:
jf go build ./... --build-name=my-go-app --build-number=1Run Go Get with No VCS Fallback
To fetch a module exclusively from Artifactory (no fallback to public VCS):
jf go get <package> --no-fallbackWhere:
<package>is the Go module path (for example,github.com/example/lib)
For example:
jf go get github.com/example/lib --no-fallbackTip
Without
--no-fallback, the CLI will fall back to the public VCS (for example, GitHub) if the module is not found in Artifactory. This is the default behavior.
Publish Build Info
After building with --build-name and --build-number, publish the collected build info to Artifactory:
jf rt build-publish <build-name> <build-number>For example:
jf rt build-publish my-go-app 1Tip
jf rt bpis a shorthand alias forjf rt build-publish.
Publish: jf go-publish
jf go-publishPublish a Go package and its dependencies to Artifactory.
To publish a Go package to Artifactory:
- Ensure
jf go-configis in place and you are in the module directory (see Configuration). - Run
jf go-publishwith the module version and any required flags (see Publish Examples).
Synopsis
jf go-publish <project-version> [options]
Aliases: gp
Arguments
| Argument | Required | Description |
|---|---|---|
<project-version> | Yes | Package version to publish (for example, v1.0.0) |
Publish Options
| Flag | Default | Description |
|---|---|---|
--build-name | — | Build name for build-info. Requires --build-number. |
--build-number | — | Build number for build-info. Requires --build-name. |
--detailed-summary | false | Set to true to include a list of affected files in the summary |
--exclusions | — | Semicolon-separated exclusions. Supports * and ? wildcards. |
--module | — | Optional module name for build-info. Requires --build-name and --build-number. |
--project | — | JFrog Artifactory project key |
--url | — | JFrog platform URL |
--user | — | JFrog username |
--password | — | JFrog password |
--access-token | — | JFrog access token |
Publish Examples
View Help
jf go-publish --helpPublish a Package Version
jf go-publish v1.0.0Publish with Build-Info and Detailed Summary
jf go-publish v1.0.0 --build-name=my-app --build-number=1 --detailed-summaryPublish with Exclusions
jf go-publish v1.0.0 --exclusions="test/*;*.md"Important Notes
- VCS fallback: By default,
--no-fallbackisfalse, meaning the CLI will fall back to the public VCS (for example, GitHub) if a module is missing in Artifactory. To enforce Artifactory-only resolution and disable VCS fallback, pass--no-fallbackor--no-fallback=true. - GOPROXY: The CLI sets
GOPROXYto point at your Artifactory Go repository. This overrides any existingGOPROXYsetting for the duration of the command. - Build-info: Use
--build-nameand--build-numberto collect dependency information, then publish withjf rt build-publish. - Version format: The version must follow Go module versioning (for example,
v1.0.0,v2.1.3). Thevprefix is required. - Exclusions: Use
--exclusionsto exclude test files, documentation, or other files you don't want in the published module.
Platform Notes
- Windows: Go module archive creation may behave differently with path separators. Use forward slashes in exclusion patterns.
- macOS / Linux:
GOPROXYenvironment variable is temporarily overridden duringjf goexecution. Check withgo env GOPROXYafter the command completes to verify it was restored.
CI/CD Example (GitHub Actions)
# .github/workflows/build.yml
steps:
- uses: actions/checkout@v4
- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@v4
env:
JF_URL: ${{ vars.JF_URL }}
JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }}
- name: Configure Go
run: jf go-config --server-id-resolve=setup-jfrog-cli-server --repo-resolve=go-virtual --server-id-deploy=setup-jfrog-cli-server --repo-deploy=go-local
- name: Build
run: jf go build --build-name=my-go-app --build-number=${{ github.run_number }} --no-fallback
- name: Publish module
run: jf go-publish v1.0.0 --build-name=my-go-app --build-number=${{ github.run_number }}
- name: Publish build info
run: jf rt build-publish my-go-app ${{ github.run_number }}Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
go: go.mod file not found or similar | jf go build/jf go-publish run outside a Go module directory | Run from the directory containing your go.mod, or initialize a module with go mod init <module-path> |
401 Unauthorized on jf go get | Access token is a reference token (non-JWT); Go proxy requires valid credentials | Re-run jf config add and provide a username, or use a JWT access token |
no config file was found | jf go-config was not run | Run jf go-config in the project directory |
404 on jf go build | Resolution repository does not exist or module not cached | Verify --repo-resolve matches an existing Go virtual repository; add --no-fallback to prevent VCS fallback |
| 401 / 403 errors | Invalid credentials or insufficient permissions | Re-run jf config add with a valid access token |
| Module version rejected by Artifactory | Version does not follow vX.Y.Z format | Ensure the version starts with v (for example, v1.0.0) |
GOPROXY conflicts | Existing GOPROXY overridden during CLI execution | The CLI sets GOPROXY temporarily; this is expected behavior |
jf go-publish uploads unwanted files | Test or doc files included | Use --exclusions="test/*;*.md" to exclude them |
Enable debug logging: export JFROG_CLI_LOG_LEVEL=DEBUG
Related Topics
- Build Tools Overview — Capabilities matrix and tool reference
- Native Mode — Supported packages with Native Mode
Updated 14 days ago
