tech:notes_gitlab-ci_pipeline_-_api
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:notes_gitlab-ci_pipeline_-_api [2026/06/17 17:45] – Jean-Baptiste | tech:notes_gitlab-ci_pipeline_-_api [2026/07/16 13:25] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| < | < | ||
| - | {{tag> | + | {{tag> |
| # Notes Gitlab-ci pipeline - API | # Notes Gitlab-ci pipeline - API | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| Ligne 20: | Ligne 24: | ||
| --header " | --header " | ||
| --header " | --header " | ||
| - | --data '{ " | + | --data '{ " |
| - | --url "http:// | + | --url "${CI_API_V4_URL}/ |
| ~~~ | ~~~ | ||
| Voir https:// | Voir https:// | ||
| + | |||
| + | |||
| + | ### Notes | ||
| + | |||
| + | CI_API_V4_URL est une variable magique dont la valeur est de la forme : `http:// | ||
| + | |||
| + | Dans notre cas la variable `ref` correspond au nom de la branche | ||
| Ligne 34: | Ligne 45: | ||
| Voir aussi : | Voir aussi : | ||
| * https:// | * https:// | ||
| + | * https:// | ||
| Aller dans le projet, puis Settings/ CI/CD / Pipeline trigger tokens | Aller dans le projet, puis Settings/ CI/CD / Pipeline trigger tokens | ||
| Ligne 41: | Ligne 53: | ||
| curl --request POST \ | curl --request POST \ | ||
| | | ||
| - | | + | |
| | | ||
| | | ||
| | | ||
| | | ||
| - | " | + | " |
| ~~~ | ~~~ | ||
| + | |||
| + | Avec Ansible | ||
| + | |||
| + | `.gitlab-ci.yml` | ||
| + | ~~~yaml | ||
| + | launch: | ||
| + | tags: | ||
| + | # - gitlab-runner-sh-001 | ||
| + | - gitlab-runner-docker-001 | ||
| + | image: registry.acme.local/ | ||
| + | stage: build | ||
| + | script: ansible-playbook play-launch-ci.yml -e url=" | ||
| + | ~~~ | ||
| + | |||
| + | `play-launch-ci.yml` | ||
| + | ~~~yaml | ||
| + | #! / | ||
| + | |||
| + | --- | ||
| + | |||
| + | - name: Launch CI | ||
| + | gather_facts: | ||
| + | hosts: localhost | ||
| + | |||
| + | vars: | ||
| + | branch: "{{ lookup(' | ||
| + | line: "{{ lookup(' | ||
| + | kind: "{{ lookup(' | ||
| + | |||
| + | tasks: | ||
| + | - name: Assert check environment vars are correctly defined | ||
| + | ansible.builtin.assert: | ||
| + | that: | ||
| + | - url is defined and url != '' | ||
| + | - token is defined and token != '' | ||
| + | - branch is defined and branch != '' | ||
| + | - line is defined and line != '' | ||
| + | - kind is defined and kind != '' | ||
| + | msg: "Env var must be defined" | ||
| + | |||
| + | - name: Call API | ||
| + | # no_log: true | ||
| + | register: reg_uri | ||
| + | until: reg_uri.status == 201 | ||
| + | retries: 3 | ||
| + | delay: 5 # Every 5 seconds | ||
| + | ansible.builtin.uri: | ||
| + | url: "{{ url }}/ | ||
| + | # validate_certs: | ||
| + | status_code: | ||
| + | follow_redirects: | ||
| + | method: POST | ||
| + | body_format: | ||
| + | headers: | ||
| + | Content-Type: | ||
| + | body: | | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| Voir https:// | Voir https:// | ||
| + | ### Autres | ||
| + | ~~~yaml | ||
| + | 000-colo-switch: | ||
| + | stage: deploy | ||
| + | variables: | ||
| + | PROJECT: " | ||
| + | rules: # whether to include the job in the pipeline | ||
| + | - if: $CI_PIPELINE_SOURCE == " | ||
| + | when: always | ||
| + | - when: never | ||
| + | ~~~ | ||
| + | Source: https:// | ||
tech/notes_gitlab-ci_pipeline_-_api.1781711159.txt.gz · Dernière modification : de Jean-Baptiste
