cargo publish "no token found, please run cargo login" in CI
cargo found no credentials for the registry, so it cannot publish. In CI you supply the crates.io token through the CARGO_REGISTRY_TOKEN environment variable rather than an interactive cargo login.
What this error means
cargo publish fails with "error: no token found, please run cargo login or pass --token" because the runner has no stored crates.io credential.
error: no token found, please run `cargo login`
or pass `--token <TOKEN>` as a command-line argumentCommon causes
No token configured on the runner
CI containers have no crates.io login. Without CARGO_REGISTRY_TOKEN or cargo login, cargo has no token to send.
The secret was not exposed to the publish step
The token secret exists but was never wired into the step env, so cargo sees nothing.
How to fix it
Set CARGO_REGISTRY_TOKEN from a secret
Expose the crates.io token via the standard environment variable; cargo reads it automatically.
- run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}Or pass the token inline
For a one-off, pass the token directly with --token. Prefer the env var so the value is not in shell history or logs.
cargo publish --token "$CARGO_REGISTRY_TOKEN"How to prevent it
- Provide CARGO_REGISTRY_TOKEN from a CI secret on every publish job.
- Never commit the crates.io token to the repo.
- Rotate the token periodically and update the secret in one place.