ドキュメントに関する現在のご利用体験についてお聞かせください。アンケートにご協力ください。
glab service-account token create
Create a token for a service account.
Synopsis
Create a personal access token for a service account of a project or a group.
- The token value is printed only once and cannot be retrieved later. It is the only output on stdout, and the token details go to stderr.
- At least one scope is required. For the scopes you can grant, see https://docs.gitlab.com/security/tokens/access_token_scopes/.
- The token expires after
--duration, 30 days by default, at 00:00 UTC. Use--expires-atfor a specific date instead. - A numeric account argument is always treated as an ID.
glab service-account token create <account-id | username> <name> [flags]Examples
# Create a token for service account 42 of the current project
glab service-account token create 42 ci --scope api
# Create a read-only token that expires in a week, finding the account by its username
glab service-account token create release-bot ci-reader --scope read_api,read_repository --duration 7d
# Create a token for a group's service account that expires at the end of 2027
glab service-account token create 42 deploy --scope api --expires-at 2027-12-31 --group my-group
# Create a token and store its value in a variable
TOKEN=$(glab service-account token create 42 ci --scope api)
Options
--description string Description of the token.
-D, --duration duration Sets the token lifetime in days. Accepts: days (30d), weeks (4w), or hours in multiples of 24 (24h, 168h, 720h). Maximum: 365d. The token expires at midnight UTC on the calculated date. (default 30d)
-E, --expires-at time Expiry date of the token, as YYYY-MM-DD. The token expires at midnight UTC on that date.
-g, --group group Create a token for a service account of a group instead of a project. Accepts a group ID or full path.
--jq string Filter JSON output with a jq expression.
-F, --output string Format output as 'text' for the token value, 'json' for the token with its details. (default "text")
-R, --repo string Select another repository. You can use either OWNER/REPO or GROUP/NAMESPACE/REPO. The full URL or Git URL is also accepted.
-S, --scope strings Scope to grant the token. Multiple scopes can be comma-separated or specified by repeating the flag.Options inherited from parent commands
-h, --help Show help for this command.Was this page helpful?