docs: document CI Lint usage · python-gitlab/python-gitlab@d5de4b1 · GitHub
Skip to content

Commit d5de4b1

Browse files
nejchJohnVillalovos
authored andcommitted
docs: document CI Lint usage
1 parent 3f67c4b commit d5de4b1

5 files changed

Lines changed: 98 additions & 43 deletions

File tree

docs/api-objects.rst

Lines changed: 1 addition & 0 deletions

docs/cli-examples.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,48 @@ CLI examples
66

77
For a complete list of objects and actions available, see :doc:`/cli-objects`.
88

9+
CI Lint
10+
-------
11+
12+
Lint a CI YAML configuration from a string:
13+
14+
.. note::
15+
16+
To see output, you will need to use the ``-v``/``--verbose`` flag.
17+
18+
.. code-block:: console
19+
20+
$ gitlab --verbose ci-lint create --content \
21+
"---
22+
test:
23+
script:
24+
- echo hello
25+
"
26+
27+
Lint a CI YAML configuration from a file (see :ref:`cli_from_files`):
28+
29+
.. code-block:: console
30+
31+
$ gitlab --verbose ci-lint create --content @.gitlab-ci.yml
32+
33+
Lint a project's CI YAML configuration:
34+
35+
.. code-block:: console
36+
37+
$ gitlab --verbose project-ci-lint create --project-id group/my-project --content @.gitlab-ci.yml
38+
39+
Lint a project's current CI YAML configuration:
40+
41+
.. code-block:: console
42+
43+
$ gitlab --verbose project-ci-lint get --project-id group/my-project
44+
45+
Lint a project's current CI YAML configuration on a specific branch:
46+
47+
.. code-block:: console
48+
49+
$ gitlab --verbose project-ci-lint get --project-id group/my-project --ref my-branch
50+
951
Projects
1052
--------
1153

docs/cli-usage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ Example:
288288
289289
$ gitlab -o yaml -f id,permissions -g elsewhere -c /tmp/gl.cfg project list
290290
291+
.. _cli_from_files:
292+
291293
Reading values from files
292294
-------------------------
293295

docs/gl_objects/ci_lint.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#######
2+
CI Lint
3+
#######
4+
5+
Reference
6+
---------
7+
8+
* v4 API:
9+
10+
+ :class:`gitlab.v4.objects.CiLint`
11+
+ :class:`gitlab.v4.objects.CiLintManager`
12+
+ :attr:`gitlab.Gitlab.ci_lint`
13+
+ :class:`gitlab.v4.objects.ProjectCiLint`
14+
+ :class:`gitlab.v4.objects.ProjectCiLintManager`
15+
+ :attr:`gitlab.v4.objects.Project.ci_lint`
16+
17+
* GitLab API: https://docs.gitlab.com/ee/api/lint.html
18+
19+
Examples
20+
---------
21+
22+
Validate a CI YAML configuration::
23+
24+
gitlab_ci_yml = """.api_test:
25+
rules:
26+
- if: $CI_PIPELINE_SOURCE=="merge_request_event"
27+
changes:
28+
- src/api/*
29+
deploy:
30+
extends:
31+
- .api_test
32+
rules:
33+
- when: manual
34+
allow_failure: true
35+
script:
36+
- echo "hello world"
37+
"""
38+
lint_result = gl.ci_lint.create({"content": gitlab_ci_yml})
39+
40+
print(lint_result.status) # Print the status of the CI YAML
41+
print(lint_result.merged_yaml) # Print the merged YAML file
42+
43+
Validate a project's CI configuration::
44+
45+
lint_result = project.ci_lint.get()
46+
assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid
47+
print(lint_result.merged_yaml) # Print the merged YAML file
48+
49+
Validate a CI YAML configuration with a namespace::
50+
51+
lint_result = project.ci_lint.create({"content": gitlab_ci_yml})
52+
assert lint_result.valid is True # Test that the .gitlab-ci.yml is valid
53+
print(lint_result.merged_yaml) # Print the merged YAML file

docs/gl_objects/projects.rst

Lines changed: 0 additions & 43 deletions

0 commit comments

Comments
 (0)