Skip to main content

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_TOKEN is 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​

NameDefaultDescription
nameRequiredSuffix used for the generated glab:<name> job.
scriptRequiredString containing one or more shell commands run after authentication.
stage.prePipeline stage for the generated job.
allow-failurefalseWhether GitLab may continue when the job fails.
needs[]Jobs whose completion or artifacts this job requires.
tags[]Runner tags for the generated job.
ruleswhen: alwaysGitLab rules controlling when the job is created.

Inputs​

NameDescriptionDefaultType
------------
allow-failureShould the pipeline fail if the test fails?falseboolean
nameThe name of the job.string
needsThe needs that this job depends on.[]array
rulesThe jobs that this job depends on.[{"when":"always"}]array
scriptThe script to run.string
stageThe name of the stage..prestring
tagsThe runners that this job depends on.[]array