GitLab CLI component
Run authenticated glab commands in a
GitLab CI job. The component uses the CI Tools tools image, loads the common
CI helper library, configures glab for the current GitLab host, and then runs
the supplied script.
Usage
Include common before glab, give each generated job a unique name, and
provide the commands through script.
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/glab@stable
inputs:
name: project-details
stage: test
script: |
glab repo view
glab api projects/:fullpath | jq '{path_with_namespace, visibility}'
The generated job is named glab:<name>. Use distinct names when including
the component more than once.
Authentication
The job configures glab for $CI_SERVER_FQDN automatically.
- When
GITLAB_TOKENis set, the component uses that token. - Otherwise, it uses the job's
$CI_JOB_TOKEN.
Prefer the job token for read-only operations and actions supported by GitLab
job-token permissions. Define GITLAB_TOKEN as a masked, protected CI/CD
variable only when the job needs an API capability unavailable to the job
token. Give that token the narrowest practical scope, and restrict the job with
rules when it can change GitLab state.
Examples
Query the current project
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/glab@stable
inputs:
name: inspect-project
stage: test
script: |
glab api projects/:fullpath |
jq -e '.path_with_namespace == env.CI_PROJECT_PATH'
Run only on the default branch
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/glab@stable
inputs:
name: default-branch-task
stage: deploy
script: glab api projects/:fullpath
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
Inputs
| Name | Default | Description |
|---|---|---|
name | Required | Suffix used for the generated glab:<name> job. |
script | Required | String containing one or more shell commands run after authentication. |
stage | .pre | Pipeline stage for the generated job. |
allow-failure | false | Whether GitLab may continue when the job fails. |
needs | [] | Jobs whose completion or artifacts this job requires. |
tags | [] | Runner tags for the generated job. |
rules | when: always | GitLab rules controlling when the job is created. |
Inputs
| Name | Description | Default | Type |
| --- | --- | --- | --- |
| allow-failure | Should the pipeline fail if the test fails? | false | boolean |
| name | The name of the job. | string | |
| needs | The needs that this job depends on. | [] | array |
| rules | The jobs that this job depends on. | [{"when":"always"}] | array |
| script | The script to run. | string | |
| stage | The name of the stage. | .pre | string |
| tags | The runners that this job depends on. | [] | array |