https://gitlab.com/nickshine/glt
A command-line interface for GitLab tasks.
npm install -g glt
# or
npx glt
Usage: glt [options] [command]
A cli for GitLab tasks
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
ci perform GitLab CI tasks
env perform tasks on GitLab environments
help [cmd] display help for [cmd]
Usage: glt-ci [options] [command]
perform GitLab CI tasks
Options:
-h, --help output usage information
Commands:
cancel cancel pipelines
help [cmd] display help for [cmd]
Usage: glt-env [options] [command]
perform tasks on GitLab Environments
Options:
-h, --help output usage information
Commands:
clean clean environments
stop stop environments
help [cmd] display help for [cmd]
โ glt ci cancel --help
Usage: glt-ci-cancel [options]
cancel pipelines
Options:
-u, --url <url> GitLab instance (default: '$GITLAB_URL' || 'https://gitlab.com')
-t, --token <token> GitLab Personal Access Token used to authenticate with the API (default: '$GITLAB_TOKEN'|| '$CI_JOB_TOKEN')
-v, --verbose make the operation more talkative
-p, --project-id <id> GitLab project id (default: '$CI_PROJECT_ID')
-i, --pipeline-id <id> cancel pipelines before pipeline id <id> (default: '$CI_PIPELINE_ID')
-b, --ref <ref> only look at pipelines on branch <ref> (default: '$CI_COMMIT_REF_NAME' || 'master')
-h, --help output usage information
Description: cancel any previously-running pipelines on the given branch.
This task is intended to be run in a GitLab CI pipeline to reference CI_PIPELINE_ID
as the
currently running pipeline.
Use Case: GitLab CI currently (as of 11.x) only has the option to auto-cancel pending non-HEAD pipelines on a branch. This task is useful for controlling runner availability for redundant running pipelines on a branch.
Usage: glt-env-clean [options]
clean environments (delete environments with zero deployments)
Options:
-u, --url <url> GitLab instance (default: '$GITLAB_URL' || 'https://gitlab.com')
-t, --token <token> GitLab Personal Access Token used to authenticate with the API (default: '$GITLAB_TOKEN'|| '$CI_JOB_TOKEN')
-v, --verbose make the operation more talkative
-p, --project-id <id> GitLab project id (default: '$CI_PROJECT_ID')
-h, --help output usage information
Description: remove any existing environments that are "empty" (environments with zero deployments).
Use Case: Projects that have optional pipelines configured (with a manual play button trigger) will generate empty environments for each commit pushed that is not executed/deployed, creating lots of "empty" environments that need to be deleted.
Usage: glt-env-stop [options]
stop environments with deployments older than a specified age
Options:
-u, --url <url> GitLab instance (default: '$GITLAB_URL' || 'https://gitlab.com')
-t, --token <token> GitLab Personal Access Token used to authenticate with the API (default: '$GITLAB_TOKEN'|| '$CI_JOB_TOKEN')
-v, --verbose make the operation more talkative
-p, --project-id <id> GitLab project id (default: '$CI_PROJECT_ID')
-a, --age <age> stop environmments with deployments older than <age> (default: "1w")
-h, --help output usage information
Description: stop environments that only have deployments older than a specified age.
Use Case: Projects utilizing dynamic environments via the Gitlab Review Apps feature may need to control environment quotas by forcing an environment of a certain age to be stopped and cleaned up.
In a GitLab CI pipeline, the following example will use GitLab Predefined environment variables to cancel any redundant running pipelines before executing tests. Running pipelines older than CI_PIPELINE_ID
on project CI_PROJECT_ID
for the the current branch CI_COMMIT_REF_NAME
will be canceled using a provided Personal Access Token set on environment variable GITLAB_TOKEN
.
image: node:10
stages:
- test
variables:
GITLAB_TOKEN: $ACCESS_TOKEN # ACCESS_TOKEN stored in project env vars
test:
stage: test
script:
- npx glt ci cancel -v
- npm install
- npm run test
This example cancels all running pipelines on a branch my-branch
for a project
at https://gitlab.com. This is run outside of a GitLab CI pipeline, using the
command-line flags:
TOKEN=<personal access token>
PROJECT_ID=<project id from gitlab.com>
npm install -g glt
glt ci cancel -t $TOKEN -p $PROJECT_ID -b my-branch -v
In a GitLab CI pipeline, the following example will stop environments with no
deployments younger than 1 week old on project CI_PROJECT_ID
using a provided
Personal Access Token set on environment variable GITLAB_TOKEN
.
image: node:10
stages:
- test
variables:
GITLAB_TOKEN: $ACCESS_TOKEN # ACCESS_TOKEN stored in project env vars
deploy:
stage: deploy
script:
- npx glt env stop -a 1w
- kubectl apply -f deployment.yaml
Contributions are welcome! Help add tasks to glt
! See the Contributing Guide.