0
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?

Jira に curl から Issue の作成および Comments の追加をしてみる

0
Posted at

ira を始めて使った時のメモ
また、API で操作を行うまでをやってみる

始めに

  • アカウント作成
  • Jira を作成
  • 適当な Space を作成

API キーの発行

Issue を API から作る

とりあえず簡単に試したいので curl で試す

# 1. 環境変数をセット(自分の値に置き換える)
export JIRA_DOMAIN="myteam"
export JIRA_EMAIL="taro@example.com"
export JIRA_API_TOKEN="..."
export JIRA_PROJECT_KEY="DOA"

# 2. Issue を作成
curl -X POST "https://${JIRA_DOMAIN}.atlassian.net/rest/api/3/issue" \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic $(echo -n "${JIRA_EMAIL}:${JIRA_API_TOKEN}" | base64)" \
  -d '{
    "fields": {
      "project": { "key": "'"${JIRA_PROJECT_KEY}"'" },
      "summary": "[Test] DevOps Agent Investigation Created",
      "description": {
        "type": "doc",
        "version": 1,
        "content": [
          {
            "type": "paragraph",
            "content": [
              { "type": "text", "text": "This is a test issue created via API." }
            ]
          }
        ]
      },
      "issuetype": { "name": "Bug" }
    }
  }'
{"id":"10001","key":"KAN-2","self":"https://EXAMPLE.atlassian.net/rest/api/3/issue/10001"}                                                                ➜  ~

成功すると Web アプリからも確認できる

Comments を追加してみる

URL 配下の形式

https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/comment

issueIdOrKey は Issue 作成時のレスポンスから確認できているのでコレを使う

curl -X POST "https://${JIRA_DOMAIN}.atlassian.net/rest/api/3/issue/KAN-2/comment" \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic $(echo -n "${JIRA_EMAIL}:${JIRA_API_TOKEN}" | base64)" \
  -d '{
    "body": {
      "type": "doc",
      "version": 1,
      "content": [
        {
          "type": "paragraph",
          "content": [
            { "type": "text", "text": "Investigation completed. Root cause: High CPU due to memory leak in service X." }
          ]
        }
      ]
    }
  }'

OK

0
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
0
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?