1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

背景

業務の中でansibleで自動的にGitlabのIssueを作成させる機会があったため、
備忘録的にplaybook等についてまとめておきます。

利用したもの

  • Ansible
  • Gitlab

プログラム

汎用的なソースコードを以下に記載します。

  • Playbook
main.yml
---
- name: GitLab issue variable 
  hosts: localhost
  vars:
    gitlab_api_token: "GitLabのAPIトークン"
    gitlab_project_id: "GitLabのIssue作成先プロジェクトID"
    gitlab_server: "GitLabサーバIPアドレス"
    issue_title: "Issueのtitle"
    issue_description: "Issueのdescription"
    issue_labels: "付与するラベル名"

  tasks:
    - name: Create Gitlab issue
      uri:
        url: "https://{{ gitlab_server }}/api/v4/projects/{{ gitlab_project_id }}/issues"
        method: POST
        headers:
          "PRIVATE-TOKEN": "{{ gitlab_api_token }}"
        body_format: json
        body:
          title: "{{ issue_title }} "
          description: "{{ issue_description }} "
          labels: "{{ issue_labels }}"
        status_code: 201
        validate_certs: no
      register: new_issue

また、既存のIssueをiidで指定して、更新することも可能です。

    - name: Update issue title with issue ID
      uri:
        url: "https://{{ gitlab_server }}/api/v4/projects/{{ gitlab_project_id }}/issues/{{ new_issue.json.iid }}"
        method: PUT
        headers:
          "PRIVATE-TOKEN": "{{ gitlab_api_token }}"
        body_format: json
        body:
          title: "{{ issue_new_title }}"
        validate_certs: no
      register: update_issue

工夫点

ansibleで自動でGitLabのIssueを作成することで、手動で実施する手間を省くだけでなく、入力ミスなどを防ぎました

終わりに

今回、GitLabのIssueの作成を実施しましたが、既存のIssueに対する処理や、クローズ処理なども自動化してより業務の効率化を図っていきたいと思います。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?