Skip to main content
Glama
owayo

https://github.com/owayo/gitlab-mcp-server

get_pipeline_failed_jobs

Retrieve console output for failed jobs in GitLab pipelines to identify and resolve build issues.

Instructions

GitLabパイプラインで失敗したジョブのコンソール出力を取得

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • main.py:46-60 (handler)
    The handler function implementing the 'get_pipeline_failed_jobs' MCP tool. Decorated with @mcp.tool() for registration. Retrieves current MR ID, fetches failed jobs output using helper, and formats response.
    @mcp.tool() def get_pipeline_failed_jobs() -> str: """GitLabパイプラインで失敗したジョブのコンソール出力を取得""" mr_id = get_current_mr_id() failed_jobs_output = get_failed_jobs_output(mr_id=mr_id) if failed_jobs_output: return f""" パイプラインで以下のエラーが出ています。 プロダクトコードの修正で対応が可能な場合は修正を行ってください。 {failed_jobs_output} """ else: return "パイプラインで失敗したジョブが見つかりません。"
  • Helper function that implements the core logic of fetching console output from failed jobs in the latest pipeline of a GitLab MR. Called by the tool handler.
    def get_failed_jobs_output(mr_id: int) -> str: """ 指定したMR IDに関連する最後のパイプラインで失敗したジョブのコンソール出力を取得します。 最後のパイプラインに失敗したジョブがなければ、空の文字列を返します。 Args: mr_id (int): Merge Request ID Returns: str: 失敗したジョブのコンソール出力、または空文字列 Raises: ValueError: ジョブ出力の取得に失敗した場合 """ try: project = get_gitlab_project() # MRを取得 mr = project.mergerequests.get(mr_id) # パイプライン情報を取得 if not hasattr(mr, "pipelines") or not mr.pipelines: return "" # パイプラインを取得し、最新のものを選択 pipelines = mr.pipelines.list() if not pipelines: return "" # 最新のパイプラインを取得 (GitLabのAPIはデフォルトで降順) latest_pipeline = pipelines[0] pipeline_detail = project.pipelines.get(latest_pipeline.id) # 失敗したジョブを検索 failed_jobs = [ job for job in pipeline_detail.jobs.list() if job.status == "failed" ] if not failed_jobs: return "" # 失敗したジョブがない場合は空文字列を返す # 失敗したジョブのコンソール出力を取得 outputs = [] for job in failed_jobs: job_detail = project.jobs.get(job.id) job_output = job_detail.trace() outputs.append( f"# ジョブ: {job.name}\n- ステータス: {job.status}\n- 出力:\n```\n{job_output}\n```" ) return "\n\n".join(outputs) except gitlab.exceptions.GitlabGetError: raise ValueError(f"MR ID #{mr_id} が見つかりません。") except Exception as e: raise ValueError(f"失敗したジョブの出力取得に失敗しました: {str(e)}")
  • main.py:31-43 (helper)
    Helper function to get the current Merge Request ID from the current branch, used by the tool handler.
    def get_current_mr_id() -> int: """ 現在のブランチのMRIDを取得します。 Returns: int: 現在のブランチのMRID """ branch_name = get_current_branch() mr = get_merge_request(branch_name) if mr: return mr.iid else: return "現在のブランチに関連するMerge Requestが見つかりません。"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/owayo/gitlab-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server