This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:git:gitlab:api:examples [2022/05/18 06:29] – mb | dev:git:gitlab:api:examples [2022/05/18 08:45] (current) – mb | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Using Gitlab API ====== | ====== Using Gitlab API ====== | ||
- | With the given gitlab api many things are possible, for example the exploration of projects and groups as well as triggering pipelines. \\ Unlike other web-sources the api refers to project- and group-IDs. These IDs are shown in the gitlab web-UI. \\ | + | With the given gitlab api many things are possible, for example the exploration of projects and groups as well as triggering pipelines. \\ |
- | To have project access with api a Token is necessary. To create a Token, go to project (or group) " | + | Unlike other web-sources the api refers to project- and group-IDs. These IDs are shown in the gitlab web-UI. \\ |
+ | To have project access with api a Token is necessary. To create a Token, go to project (or group) " | ||
+ | Tokens have an expiration date, but with leaving it blank, no expiration date is set. \\ | ||
+ | **Tokens can not be seen after creation so save it locally!** | ||
==== Exploring groups via API ==== | ==== Exploring groups via API ==== | ||
For a better overview and prettier output Postman is used. \\ | For a better overview and prettier output Postman is used. \\ | ||
==== Exploring projects via API ==== | ==== Exploring projects via API ==== | ||
+ | To start exploring a project, create a access token and get the project ID. In this example project " | ||
<Code: shell linenums:0 | cURL example to access project root> | <Code: shell linenums:0 | cURL example to access project root> | ||
- | curl --location --request GET ' | + | curl --location --request GET ' |
</ | </ | ||
+ | Obviously a cURL command isn't perfect for exploration, | ||
+ | Nonetheless there are many possibilities with cURL when using Pipelines to process the output. Requests can also be sent and processed with other program languages like python or perl. \\ | ||
+ | With the api files are also accessable: \\ | ||
+ | <Code: shell linenums:0 | cURL example to access project root> | ||
+ | curl --location --request GET ' | ||
+ | </ | ||
+ | With this snippet we can get the file " | ||
+ | The project tags can be shown as well, see example below. \\ | ||
+ | {{ : | ||
+ | <wrap hi> | ||
+ | With this api call, all project tags as well as more information about the tag, like creation date and user. \\ | ||
==== Trigger a pipeline via API ==== | ==== Trigger a pipeline via API ==== | ||
First go to project settings -> " | First go to project settings -> " | ||
- | After enabling pipeline triggers for a project the given token is used as variable in the trigger request. \\ As you can see after creating this token, cURL examples | + | After enabling pipeline triggers for a project the given token is used as variable in the trigger request. Unlike previous used api calls, a <wrap hi> |
- | \\ {{: | + | As you can see after creating this token, cURL examples |
- | With Postman we also have a better overview about the sent variables. These can also be seen in the created pipeline, as seen below. \\ It is also possible to overwrite Gitlab CI variables, these are only set in this running job. | + | \\ {{ : |
- | {{: | + | With Postman we also have a better overview about the sent variables. These can also be seen in the created pipeline, as seen below. \\ |
+ | It is also possible to overwrite Gitlab CI variables, these are only set in this running job. | ||
+ | {{ : |