Gitlab CI Variables Setter CLI
CLI tool to allow setting/getting pipeline variables on Gitlab CI.
Supports Gitlab API v4, available since Gitlab 9.0.
Installation
Install the tool globally for ease of use, by running the following command
$ npm install -g gitlab-ci-variables-cli
Usage
glci set
)
Set one variable (Run the following command, where:
gitlab-token
is your Gitlab personal access tokengitlab-project-url
is your project url on gitlab, e.g. https://gitlab.com/gitlab-org/gitlab-cekey
is the variable you want to setvalue
is the value of the variable you want to set
$ glci set --token <gitlab-token> --url <gitlab-project-url> --key <key> --value <value>Set <key> = <value>
glci setAll
)
Set several variables (Put all required variable key/values on a properties file named gitlab.env.yml
, e.g:
AWS_CREDENTIALS: | [canary] aws_access_key_id = AKIA1234 aws_secret_access_key = verySecretKeyNPM_INSTALL_TOKEN: 123456789
Note that the value for
AWS_CREDENTIALS
is a multi line string (with spaces and no tabs).
Run the following command from the directory that contains the properties file.
$ glci setAll --token <gitlab-token> --url <gitlab-project-url>Set AWS_CREDENTIALS = <value>
gitlab-token
is your Gitlab personal access tokengitlab-project-url
is your project url on gitlab, e.g. https://gitlab.com/gitlab-org/gitlab-ce
glci getAll
)
Get all variables (Download all variable key/value pairs to a properties file.
Run the following command:
$ glci getAll --token <gitlab-token> --url <gitlab-project-url> --output result.ymlDownloaded variables from Gitlab CI.Saved variables to result.yml
gitlab-token
is your Gitlab personal access tokengitlab-project-url
is your project url on gitlab, e.g. https://gitlab.com/gitlab-org/gitlab-ce
Note that if you do not specify
output
, then the properties file will be saved togitlab.env.yml
in the current directory.
For all usages
--do-not-force
By default, existing variables on Gitlab CI will be overridden. If you wish to ignore existing variables, add a --do-not-force
option, e.g:
$ glci setAll --token <gitlab-token> --url <gitlab-project-url> --do-not-forceSkipping AWS_CREDENTIALS, already set
--url
If your working directory is a git repository of your project, the --url
option can be omitted, e.g:
$ glci set --token <gitlab-token> --key <key> --value <value>No URL specified, using git remote `origin`.Set <key> = <value>
Omitting
--url
will derive the URL from the remote namedorigin
.
--token
This project supports .gitlabrc
files using rc.
If --token
is not specified, this project can use a .gitlabrc
, e.g:
token = this-is-my-gitlab-token
$ glci setAll --url <gitlab-project-url>Using token from .gitlabrc.Set AWS_CREDENTIALS = <value>
Alternatively, you can also set a GITLAB_TOKEN environment variable:
$ export GITLAB_TOKEN=this-is-my-gitlab-token$ glci set --url <gitlab-project-url> --key <key> --value <value>Using token from environment variable GITLAB_TOKEN.Set <key> = <value>
Essentially, if your project is a git repository, and you have a .gitlabrc
file or a GITLAB_TOKEN env variable,
this tool can be invoked simply as:
$ glci setAllUsing token from .gitlabrc.No URL specified, using git remote `origin`.Set AWS_CREDENTIALS = <value>
$ glci set --key <key> --value <value>Using token from environment variable GITLAB_TOKEN.No URL specified, using git remote `origin`.Set <key> = <value>