正式なドキュメントは英語版であり、この日本語訳はAI支援翻訳により作成された参考用のものです。日本語訳の一部の内容は人間によるレビューがまだ行われていないため、翻訳のタイミングにより英語版との間に差異が生じることがあります。最新かつ正確な情報については、英語版をご参照ください。

パイプラインAPI

  • プラン: Free、Premium、Ultimate
  • 提供形態: GitLab.com、GitLab Self-Managed、GitLab Dedicated

このAPIを使用して、CI/CDパイプラインを操作します。

プロジェクトパイプラインのリストを取得する

プロジェクト内のパイプラインのリストを取得します。

デフォルトでは、子パイプラインは結果に含まれません。子パイプラインを返すには、sourceparent_pipelineに設定します。

GET /projects/:id/pipelines

結果のページネーションを制御するには、pageおよびper_pageページネーションパラメータを使用します。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
name文字列いいえ指定された名前のパイプラインを返します。
order_by文字列いいえパイプラインを、idstatusrefupdated_at、またはuser_idで並べ替えます(デフォルト: id)。
ref文字列いいえパイプラインのref
scope文字列いいえパイプラインのスコープ。runningpendingfinishedbranchestagsのいずれか。
sha文字列いいえパイプラインのSHA
sort文字列いいえパイプラインをascまたはdescの順にソートします(デフォルト: desc)。
source文字列いいえパイプラインソース
status文字列いいえパイプラインのステータス。createdwaiting_for_resourcepreparingpendingrunningsuccessfailedcanceledskippedmanualscheduledのいずれか。
updated_after日時いいえ指定された日付より後に更新されたパイプラインを返します。ISO 8601形式(2019-03-15T08:00:00Z)で指定します。
updated_before日時いいえ指定された日付より前に更新されたパイプラインを返します。ISO 8601形式(2019-03-15T08:00:00Z)で指定します。
created_after日時いいえ指定された日付より後に作成されたパイプラインを返します。ISO 8601形式(2019-03-15T08:00:00Z)で指定します。
created_before日時いいえ指定された日付より前に作成されたパイプラインを返します。ISO 8601形式(2019-03-15T08:00:00Z)で指定します。
username文字列いいえパイプラインをトリガーしたユーザーのユーザー名
yaml_errorsブール値いいえ無効な設定のパイプラインを返します。
curl \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines"

レスポンス例

[
  {
    "id": 47,
    "iid": 12,
    "project_id": 1,
    "status": "pending",
    "source": "push",
    "ref": "new-pipeline",
    "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
    "name": "Build pipeline",
    "web_url": "https://example.com/foo/bar/pipelines/47",
    "created_at": "2016-08-11T11:28:34.085Z",
    "updated_at": "2016-08-11T11:32:35.169Z"
  },
  {
    "id": 48,
    "iid": 13,
    "project_id": 1,
    "status": "pending",
    "source": "web",
    "ref": "new-pipeline",
    "sha": "eb94b618fb5865b26e80fdd8ae531b7a63ad851a",
    "name": "Build pipeline",
    "web_url": "https://example.com/foo/bar/pipelines/48",
    "created_at": "2016-08-12T10:06:04.561Z",
    "updated_at": "2016-08-12T10:09:56.223Z"
  }
]

単一のパイプラインを取得する

プロジェクトから1つのパイプラインを取得します。

単一の子パイプラインを取得することもできます。

GET /projects/:id/pipelines/:pipeline_id

結果のページネーションを制御するには、pageおよびper_pageページネーションパラメータを使用します。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
pipeline_id整数はいパイプラインのID
curl \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines/46"

レスポンス例

{
  "id": 287,
  "iid": 144,
  "project_id": 21,
  "name": "Build pipeline",
  "sha": "50f0acb76a40e34a4ff304f7347dcc6587da8a14",
  "ref": "main",
  "status": "success",
  "source": "push",
  "created_at": "2022-09-21T01:05:07.200Z",
  "updated_at": "2022-09-21T01:05:50.185Z",
  "web_url": "http://127.0.0.1:3000/test-group/test-project/-/pipelines/287",
  "before_sha": "8a24fb3c5877a6d0b611ca41fc86edc174593e2b",
  "tag": false,
  "yaml_errors": null,
  "user": {
    "id": 1,
    "username": "root",
    "name": "Administrator",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://127.0.0.1:3000/root"
  },
  "started_at": "2022-09-21T01:05:14.197Z",
  "finished_at": "2022-09-21T01:05:50.175Z",
  "committed_at": null,
  "duration": 34,
  "queued_duration": 6,
  "coverage": null,
  "detailed_status": {
    "icon": "status_success",
    "text": "passed",
    "label": "passed",
    "group": "success",
    "tooltip": "passed",
    "has_details": false,
    "details_path": "/test-group/test-project/-/pipelines/287",
    "illustration": null,
    "favicon": "/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"
  },
  "archived": false
}

最新のパイプラインを取得する

プロジェクト内の特定のrefにおける最新のコミット用の最新パイプラインを取得します。コミット用のパイプラインが存在しない場合、403ステータスコードが返されます。

GET /projects/:id/pipelines/latest

結果のページネーションを制御するには、pageおよびper_pageページネーションパラメータを使用します。

属性必須説明
ref文字列いいえ最新のパイプラインを確認するブランチまたはタグ。指定しない場合、デフォルトのブランチがデフォルトになります。
curl \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines/latest"

レスポンス例

{
    "id": 287,
    "iid": 144,
    "project_id": 21,
    "name": "Build pipeline",
    "sha": "50f0acb76a40e34a4ff304f7347dcc6587da8a14",
    "ref": "main",
    "status": "success",
    "source": "push",
    "created_at": "2022-09-21T01:05:07.200Z",
    "updated_at": "2022-09-21T01:05:50.185Z",
    "web_url": "http://127.0.0.1:3000/test-group/test-project/-/pipelines/287",
    "before_sha": "8a24fb3c5877a6d0b611ca41fc86edc174593e2b",
    "tag": false,
    "yaml_errors": null,
    "user": {
        "id": 1,
        "username": "root",
        "name": "Administrator",
        "state": "active",
        "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
        "web_url": "http://127.0.0.1:3000/root"
    },
    "started_at": "2022-09-21T01:05:14.197Z",
    "finished_at": "2022-09-21T01:05:50.175Z",
    "committed_at": null,
    "duration": 34,
    "queued_duration": 6,
    "coverage": null,
    "detailed_status": {
        "icon": "status_success",
        "text": "passed",
        "label": "passed",
        "group": "success",
        "tooltip": "passed",
        "has_details": false,
        "details_path": "/test-group/test-project/-/pipelines/287",
        "illustration": null,
        "favicon": "/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"
    },
    "archived": false
}

パイプライン用の変数を取得する

パイプラインのパイプライン変数を取得します。

GET /projects/:id/pipelines/:pipeline_id/variables

結果のページネーションを制御するには、pageおよびper_pageページネーションパラメータを使用します。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
pipeline_id整数はいパイプラインのID
curl \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines/46/variables"

レスポンス例

[
  {
    "key": "RUN_NIGHTLY_BUILD",
    "variable_type": "env_var",
    "value": "true"
  },
  {
    "key": "foo",
    "value": "bar"
  }
]

パイプライン用のテストレポートを取得する

このAPIルートは、単体テストレポート機能の一部です。

GET /projects/:id/pipelines/:pipeline_id/test_report

結果のページネーションを制御するには、pageおよびper_pageページネーションパラメータを使用します。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
pipeline_id整数はいパイプラインのID

リクエストのサンプル:

curl \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines/46/test_report"

応答のサンプル:

{
  "total_time": 5,
  "total_count": 1,
  "success_count": 1,
  "failed_count": 0,
  "skipped_count": 0,
  "error_count": 0,
  "test_suites": [
    {
      "name": "Secure",
      "total_time": 5,
      "total_count": 1,
      "success_count": 1,
      "failed_count": 0,
      "skipped_count": 0,
      "error_count": 0,
      "test_cases": [
        {
          "status": "success",
          "name": "Security Reports can create an auto-remediation MR",
          "classname": "vulnerability_management_spec",
          "execution_time": 5,
          "system_output": null,
          "stack_trace": null
        }
      ]
    }
  ]
}

パイプライン用のテストレポート概要を取得する

このAPIルートは、単体テストレポート機能の一部です。

GET /projects/:id/pipelines/:pipeline_id/test_report_summary

結果のページネーションを制御するには、pageおよびper_pageページネーションパラメータを使用します。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
pipeline_id整数はいパイプラインのID

リクエストのサンプル:

curl \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines/46/test_report_summary"

応答のサンプル:

{
    "total": {
        "time": 1904,
        "count": 3363,
        "success": 3351,
        "failed": 0,
        "skipped": 12,
        "error": 0,
        "suite_error": null
    },
    "test_suites": [
        {
            "name": "test",
            "total_time": 1904,
            "total_count": 3363,
            "success_count": 3351,
            "failed_count": 0,
            "skipped_count": 12,
            "error_count": 0,
            "build_ids": [
                66004
            ],
            "suite_error": null
        }
    ]
}

パイプラインを新規作成

POST /projects/:id/pipeline
属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
ref文字列はいパイプラインを実行するブランチまたはタグ。マージリクエストパイプラインの場合は、マージリクエストエンドポイントを使用します。
variables配列いいえ構造[{ 'key': 'UPLOAD_TO_S3', 'variable_type': 'file', 'value': 'true' }, {'key': 'TEST', 'value': 'test variable'}]と一致する、パイプライン使用可能な変数を含むハッシュの配列variable_typeが除外されている場合、デフォルトはenv_varになります。
inputsハッシュいいえパイプラインの作成時に使用するインプットが、キーと値のペアとして含まれているハッシュ

基本的な例:

curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipeline?ref=main"

インプットを使用したリクエストの例:

curl --request POST \
  --header "Content-Type: application/json" \
  --data '{"inputs": {"environment": "environment", "scan_security": false, "level": 3}}' \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  "https://gitlab.example.com/api/v4/projects/1/pipeline?ref=main"

レスポンス例

{
  "id": 61,
  "iid": 21,
  "project_id": 1,
  "sha": "384c444e840a515b23f21915ee5766b87068a70d",
  "ref": "main",
  "status": "pending",
  "before_sha": "0000000000000000000000000000000000000000",
  "tag": false,
  "yaml_errors": null,
  "user": {
    "name": "Administrator",
    "username": "root",
    "id": 1,
    "state": "active",
    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://localhost:3000/root"
  },
  "created_at": "2016-11-04T09:36:13.747Z",
  "updated_at": "2016-11-04T09:36:13.977Z",
  "started_at": null,
  "finished_at": null,
  "committed_at": null,
  "duration": null,
  "queued_duration": 0.010,
  "coverage": null,
  "web_url": "https://example.com/foo/bar/pipelines/61",
  "archived": false
}

パイプラインでジョブを再試行する

失敗した、またはキャンセルされたジョブをパイプラインで再試行します。失敗した、またはキャンセルされたジョブがパイプラインにない場合、このエンドポイントを呼び出しても効果はありません。

POST /projects/:id/pipelines/:pipeline_id/retry
属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
pipeline_id整数はいパイプラインのID
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines/46/retry"

応答:

{
  "id": 46,
  "iid": 11,
  "project_id": 1,
  "status": "pending",
  "ref": "main",
  "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "before_sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "tag": false,
  "yaml_errors": null,
  "user": {
    "name": "Administrator",
    "username": "root",
    "id": 1,
    "state": "active",
    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://localhost:3000/root"
  },
  "created_at": "2016-08-11T11:28:34.085Z",
  "updated_at": "2016-08-11T11:32:35.169Z",
  "started_at": null,
  "finished_at": "2016-08-11T11:32:35.145Z",
  "committed_at": null,
  "duration": null,
  "queued_duration": 0.010,
  "coverage": null,
  "web_url": "https://example.com/foo/bar/pipelines/46",
  "archived": false
}

パイプライン用のすべてのジョブをキャンセルする

POST /projects/:id/pipelines/:pipeline_id/cancel

このエンドポイントは、パイプラインの状態に関係なく、成功応答200を返します。詳細については、イシュー414963を参照してください。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
pipeline_id整数はいパイプラインのID
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines/46/cancel"

応答:

{
  "id": 46,
  "iid": 11,
  "project_id": 1,
  "status": "canceled",
  "ref": "main",
  "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "before_sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "tag": false,
  "yaml_errors": null,
  "user": {
    "name": "Administrator",
    "username": "root",
    "id": 1,
    "state": "active",
    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://localhost:3000/root"
  },
  "created_at": "2016-08-11T11:28:34.085Z",
  "updated_at": "2016-08-11T11:32:35.169Z",
  "started_at": null,
  "finished_at": "2016-08-11T11:32:35.145Z",
  "committed_at": null,
  "duration": null,
  "queued_duration": 0.010,
  "coverage": null,
  "web_url": "https://example.com/foo/bar/pipelines/46",
  "archived": false
}

パイプラインを削除する

パイプラインを削除すると、すべてのパイプラインキャッシュが期限切れになり、ビルド、ログ、アーティファクト、トリガーなど、直接関連するすべてのオブジェクトが削除されます。This action cannot be undone(この操作は元に戻すことができません。)

パイプラインを削除しても、子パイプラインは自動的に削除されません。詳細については、関連イシューを参照してください。

DELETE /projects/:id/pipelines/:pipeline_id
属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
pipeline_id整数はいパイプラインのID
curl --request DELETE \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/pipelines/46"

パイプラインのメタデータを更新する

パイプラインのメタデータを更新できます。メタデータには、パイプラインの名前が含まれています。

PUT /projects/:id/pipelines/:pipeline_id/metadata
属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
name文字列はいパイプラインの新しい名前
pipeline_id整数はいパイプラインのID

リクエストのサンプル:

curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --data "name=Some new pipeline name" "https://gitlab.example.com/api/v4/projects/1/pipelines/46/metadata"

応答のサンプル:

{
  "id": 46,
  "iid": 11,
  "project_id": 1,
  "status": "running",
  "ref": "main",
  "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "before_sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
  "tag": false,
  "yaml_errors": null,
  "user": {
    "name": "Administrator",
    "username": "root",
    "id": 1,
    "state": "active",
    "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
    "web_url": "http://localhost:3000/root"
  },
  "created_at": "2016-08-11T11:28:34.085Z",
  "updated_at": "2016-08-11T11:32:35.169Z",
  "started_at": null,
  "finished_at": "2016-08-11T11:32:35.145Z",
  "committed_at": null,
  "duration": null,
  "queued_duration": 0.010,
  "coverage": null,
  "web_url": "https://example.com/foo/bar/pipelines/46",
  "name": "Some new pipeline name",
  "archived": false
}