Skip to content

Commit 3ce575a

Browse files
committed
Improve documentation.
1 parent 90ed3c1 commit 3ce575a

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
## gitlab-ci-validate
2+
23
This tool uses GitLab's CI [config validation API endpoint](https://docs.gitlab.com/ce/api/lint.html) to validate local config files.
34

45
If you don't want to use the command line, you can paste your config into `https://gitlab.com/<your project>/-/ci/lint` [[ref](https://docs.gitlab.com/ee/ci/yaml/#validate-the-gitlab-ciyml)]
56

67
### Usage
8+
79
One or more `.gitlab-ci.yml` are passed as arguments on the command line. Any errors will result in a non-zero exit code. The filename must end in `.yml` to pass, but doesn't have to be `.gitlab-ci.yml`.
10+
An access token must be provided in order to authenticate throw gitlab API. [Here to generate one](https://gitlab.com/-/profile/personal_access_tokens).
11+
812
```text
9-
$ gitlab-ci-validate ./good.yml ./maybe-good.yml ./bad.yml
13+
$ gitlab-ci-validate --token=ACCESS_TOKEN ./good.yml ./maybe-good.yml ./bad.yml
1014
PASS: ./good.yml
1115
SOFT FAIL: ./maybe-good.yml
1216
- Post https://gitlab.com/api/v4/ci/lint: dial tcp: lookup gitlab.com on 127.0.0.53:53: read udp 127.0.0.1:41487->127.0.0.53:53: i/o timeout
@@ -16,51 +20,58 @@ HARD FAIL: ./bad.yml
1620

1721
Each input file will be validated and one of 3 results will be printed for it:
1822

19-
- _PASS_ - the file passed all checks
20-
- _SOFT FAIL_ - the file is acessable and contains valid YAML, but there was an error contacting the validation API
21-
- _HARD FAIL_ - the file failed any checks
23+
- _PASS_ - the file passed all checks
24+
- _SOFT FAIL_ - the file is acessable and contains valid YAML, but there was an error contacting the validation API
25+
- _HARD FAIL_ - the file failed any checks
2226

2327
The exit code will be:
2428

25-
- 0 if all files are valid (all _PASS_)
26-
- 1 if any files are invalid (any _HARD FAIL_)
27-
- 2 if there was any _SOFT FAIL_ and no _HARD FAIL_
29+
- 0 if all files are valid (all _PASS_)
30+
- 1 if any files are invalid (any _HARD FAIL_)
31+
- 2 if there was any _SOFT FAIL_ and no _HARD FAIL_
2832

2933
### Using private GitLab host
34+
3035
You can also use a private GitLab host both as a flag or as an environment variable.
3136
The following are equivalent.
3237

3338
```
34-
gitlab-ci-validate --host=http://user:pass@127.0.0.1:8080 .gitlab-ci.yml
39+
gitlab-ci-validate --token=ACCESS_TOKEN --host=http://user:pass@127.0.0.1:8080 .gitlab-ci.yml
3540
```
3641

3742
```
3843
export GITLAB_HOST=http://user:pass@127.0.0.1:8080
44+
export GITLAB_TOKEN=XXXXXXX
3945
gitlab-ci-validate .gitlab-ci.yml
4046
```
4147

4248
The flag has precedence over the environment variable.
4349
When not specified the host used is by default `https://gitlab.com`
4450

4551
### Installation
52+
4653
You can either use a premade binary from the [releases page](https://github.com/Code0x58/gitlab-ci-validate/releases) or you can install it using `go get`:
54+
4755
```sh
4856
go get -u github.com/Code0x58/gitlab-ci-validate
4957
```
5058

5159
#### Usage with Docker containers
60+
5261
You can use the Dockerfile to build your own image or use the pre-built version available at the [Gitlab container registry](https://gitlab.com/comedian780/docker-gitlab-ci-validate/container_registry).
5362

5463
You can run tests against the gitlab.com endpoint:
5564
If no parameter is given the container will look for a file called `.gitlab-ci.yml`
65+
5666
```sh
5767
docker run -i --rm \
5868
-v ${PWD}/.gitlab-ci.yml:/yaml/.gitlab-ci.yml \
5969
registry.gitlab.com/comedian780/docker-gitlab-ci-validate
6070
```
6171

6272
You can run tests against a self hosted Gitlab instance with custom filenames:
63-
Set the credentials and URL via the `GITLAB_HOST` environment variable
73+
Set the credentials and URL via the `GITLAB_HOST` environment variable
74+
6475
```sh
6576
docker run -i --rm \
6677
-e GITLAB_HOST=https://GITLAB_USER:GITLAB_PW@your.gitlab.server \
@@ -70,6 +81,7 @@ registry.gitlab.com/comedian780/docker-gitlab-ci-validate custom.yml .files.yaml
7081
```
7182

7283
You can also test all YAML files inside a directory (this also includes YAML files in subdirectories):
84+
7385
```sh
7486
find . -type f -regex ".*\.\(yaml\|yml\|YAML\|YML\)" | xargs echo | xargs -I {} \
7587
docker run -i --rm \

0 commit comments

Comments
 (0)