Skip to content

Commit

Permalink
tidy up code and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
quangkhoa committed Feb 9, 2018
1 parent a4b8b57 commit 48efef6
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 43 deletions.
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Travis CI](https://img.shields.io/travis/temando/gitlab-ci-variables-cli.svg)](https://travis-ci.org/temando/gitlab-ci-variables-cli)
[![MIT License](https://img.shields.io/github/license/temando/gitlab-ci-variables-cli.svg)](https://en.wikipedia.org/wiki/MIT_License)

CLI tool to allow setting pipeline variables on Gitlab CI, instead of going through Gitlab UI and adding individual variables.
CLI tool to allow setting/getting pipeline variables on Gitlab CI.

Supports Gitlab API v4, available since Gitlab 9.0.

Expand All @@ -13,12 +13,12 @@ Supports Gitlab API v4, available since Gitlab 9.0.
Install the tool globally for ease of use, by running the following command

```sh
$ npm install -g gitlab-ci-variables-setter-cli
$ npm install -g gitlab-ci-variables-cli
```

## Usage

### Save one variable (`glci sv`)
### Set one variable (`glci set`)

Run the following command, where:

Expand All @@ -28,12 +28,12 @@ Run the following command, where:
- `value` is the value of the variable you want to set

```sh
$ glci sv --token <gitlab-token> --url <gitlab-project-url> --key <key> --value <value>
$ glci set --token <gitlab-token> --url <gitlab-project-url> --key <key> --value <value>
Set <key> = <value> for gitlab-org/gitlab-ce.
Completed setting variable on Gitlab CI.
```

### Save several variables (`glci sav`)
### Set several variables (`glci setAll`)

Put all required variable key/values on a properties file named `gitlab.env.yml`, e.g:

Expand All @@ -47,42 +47,42 @@ NPM_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, where:

- `gitlab-token` is your Gitlab personal access token
- `gitlab-project-url` is your project url on gitlab, e.g. https://gitlab.com/gitlab-org/gitlab-ce
Run the following command from the directory that contains the properties file.

```sh
$ glci sav --token <gitlab-token> --url <gitlab-project-url>
$ glci setAll --token <gitlab-token> --url <gitlab-project-url>
Set AWS_CREDENTIALS = <value> for gitlab-org/gitlab-ce.
Set NPM_INSTALL_TOKEN = <value> for gitlab-org/gitlab-ce.
Completed setting variables on Gitlab CI.
```

### Load several variables (`glci lav`)

Download all variable key/values to a properties file.

Run the following command to save the properties file to `gitlab.env.yml` in the current directory or
optionally specify an alternative destination, eg.

- `gitlab-token` is your Gitlab personal access token
- `gitlab-project-url` is your project url on gitlab, e.g. https://gitlab.com/gitlab-org/gitlab-ce

### Get all variables (`glci getAll`)

Download all variable key/value pairs to a properties file.

Run the following command:
```sh
$ glci lav --token <gitlab-token> --url <gitlab-project-url> --out gitlab.env.yml
$ glci getAll --token <gitlab-token> --url <gitlab-project-url> --output result.yml
Downloaded variables from Gitlab CI.
Saved variables to gitlab.env.yml
Saved variables to result.yml
```

- `gitlab-token` is your Gitlab personal access token
- `gitlab-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 to `gitlab.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:

```sh
$ glci sav --token <gitlab-token> --url <gitlab-project-url> --do-not-force
$ glci setAll --token <gitlab-token> --url <gitlab-project-url> --do-not-force
Skipping AWS_CREDENTIALS, already set for gitlab-org/gitlab-ce.
Skipping NPM_INSTALL_TOKEN, already set for gitlab-org/gitlab-ce.
Completed setting variables on Gitlab CI.
Expand All @@ -93,7 +93,7 @@ Completed setting variables on Gitlab CI.
If your working directory is a git repository of your project, the `--url` option can be omitted, e.g:

```sh
$ glci sv --token <gitlab-token> --key <key> --value <value>
$ glci set --token <gitlab-token> --key <key> --value <value>
No URL specified, using git remote `origin`.
Set <key> = <value> for gitlab-org/gitlab-ce.
Completed setting variable on Gitlab CI.
Expand All @@ -111,7 +111,7 @@ token = this-is-my-gitlab-token
```

```sh
$ glci sav --url <gitlab-project-url>
$ glci setAll --url <gitlab-project-url>
Using token from .gitlabrc.
Set AWS_CREDENTIALS = <value> for gitlab-org/gitlab-ce.
Set NPM_INSTALL_TOKEN = <value> for gitlab-org/gitlab-ce.
Expand All @@ -122,7 +122,7 @@ Alternatively, you can also set a GITLAB_TOKEN environment variable:

```sh
$ export GITLAB_TOKEN=this-is-my-gitlab-token
$ glci sv --url <gitlab-project-url> --key <key> --value <value>
$ glci set --url <gitlab-project-url> --key <key> --value <value>
Using token from environment variable GITLAB_TOKEN.
Set <key> = <value> for gitlab-org/gitlab-ce.
Completed setting variable on Gitlab CI.
Expand All @@ -134,15 +134,15 @@ Essentially, if your project is a git repository, and you have a `.gitlabrc` fil
this tool can be invoked simply as:

```sh
$ glci sav
$ glci setAll
Using token from .gitlabrc.
No URL specified, using git remote `origin`.
Set AWS_CREDENTIALS = <value> for gitlab-org/gitlab-ce.
Set NPM_INSTALL_TOKEN = <value> for gitlab-org/gitlab-ce.
Completed setting variables on Gitlab CI.
```
```sh
$ glci sv --key <key> --value <value>
$ glci set --key <key> --value <value>
Using token from environment variable GITLAB_TOKEN.
No URL specified, using git remote `origin`.
Set <key> = <value> for gitlab-org/gitlab-ce.
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "gitlab-ci-variables-setter-cli",
"name": "gitlab-ci-variables-cli",
"version": "2.0.0",
"description": "CLI tool to allow setting pipeline variables on Gitlab CI.",
"description": "CLI tool to set/get pipeline variables on Gitlab CI.",
"author": "Khoa Tran <[email protected]>",
"contributors": [
"Brendan Abbott <[email protected]>",
"Baptiste Redon <[email protected]>"
"Baptiste Redon <[email protected]>",
"Julian Fell"
],
"license": "MIT",
"keywords": [
Expand Down
12 changes: 6 additions & 6 deletions src/glci-lav.js → src/glci-getAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ async function execute() {

console.log('Downloaded variables from Gitlab CI.');

savePropertiesFile(`${process.cwd()}/conf.out`, resp);
savePropertiesFile(`${process.cwd()}/${conf.output}`, resp);

console.log(`Saved variables to ${conf.out}`);
console.log(`Saved variables to ${conf.output}`);

return resp;
}

program
.description('Read all key/value pairs from Gitlab API and saves them to the specified .yml file')
.description('Read all key/value pairs from Gitlab API and save them to the specified output file')
.option(
'--url <url>',
'Your Gitlab project URL, e.g. https://gitlab.com/gitlab-org/gitlab-ce',
)
.option(
'--token <token>',
'Your Gitlab token.',
'Your Gitlab token',
)
.option(
'--out <out>',
'The location to save CI values to.',
'--output <output>',
'The location to save the result to',
'gitlab.env.yml',
)
.parse(process.argv);
Expand Down
6 changes: 3 additions & 3 deletions src/glci-sv.js → src/glci-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ program
)
.option(
'--token <token>',
'Your Gitlab token.',
'Your Gitlab token',
)
.option(
'--key <key>',
'Your Gitlab CI variable.',
'Your Gitlab CI variable',
)
.option(
'--value <value>',
'Your Gitlab CI value.',
'Your Gitlab CI value',
)
.option(
'--do-not-force',
Expand Down
2 changes: 1 addition & 1 deletion src/glci-sav.js → src/glci-setAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ program
)
.option(
'--token <token>',
'Your Gitlab token.',
'Your Gitlab token',
)
.option(
'--do-not-force',
Expand Down
6 changes: 3 additions & 3 deletions src/glci.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import npmPackage from '../package.json';

program
.version(npmPackage.version)
.command('sv', 'set a variable')
.command('sav', 'set all variables')
.command('lav', 'load all variables')
.command('set', 'set a variable')
.command('setAll', 'set all variables')
.command('getAll', 'load all variables')
.parse(process.argv);

if (!process.argv.slice(1).length) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async function getConf() {
}
}

if (!conf.out) {
conf.out = gitlabEnvFileName;
if (!conf.output) {
conf.output = gitlabEnvFileName;
}

if (errors.length > 0) {
Expand Down

0 comments on commit 48efef6

Please sign in to comment.