Skip to main content
Glama

get_job_log

Retrieve execution logs for GitLab CI/CD jobs to monitor pipeline status and debug failures. Specify project and job IDs to access log content.

Instructions

取得 Job 的執行日誌

Args: project_id: 專案 ID 或路徑 job_id: Job ID last_lines: 只顯示最後 N 行(0 表示全部,預設 0)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
job_idYes
last_linesNo

Implementation Reference

  • The tool definition and implementation in the MCP server layer.
    @mcp.tool()
    def get_job_log(project_id: int | str, job_id: int, last_lines: int = 0) -> str:
        """取得 Job 的執行日誌
    
        Args:
            project_id: 專案 ID 或路徑
            job_id: Job ID
            last_lines: 只顯示最後 N 行(0 表示全部,預設 0)
        """
        try:
            client = get_client()
            log = client.get_job_log(project_id, job_id)
    
            if not log:
                return f"Job #{job_id} 沒有日誌"
    
            if last_lines > 0:
                log_lines = log.splitlines()
                if len(log_lines) > last_lines:
                    log = "\n".join(log_lines[-last_lines:])
                    return f"Job #{job_id} 日誌(最後 {last_lines} 行,共 {len(log_lines)} 行):\n\n{log}"
    
            # 截斷過長的日誌
            if len(log) > 50000:
                log = log[:50000] + "\n\n... (日誌已截斷,共 " + str(len(log)) + " 字元,請使用 last_lines 參數限制輸出)"
    
            return f"Job #{job_id} 日誌:\n\n{log}"
        except GitLabAPIError as e:
            return f"取得日誌失敗: {str(e)}"
    
    
    @mcp.tool()
    def retry_job(project_id: int | str, job_id: int) -> str:
        """重試單一 Job
    
        Args:
  • The underlying GitLab API call implementation for fetching job logs.
    def get_job_log(self, project_id: int | str, job_id: int) -> str:
        """GET /projects/:id/jobs/:job_id/trace — 回傳純文字日誌"""
        pid = self._resolve_project_id(project_id)
        return self._get_text(f"/projects/{pid}/jobs/{job_id}/trace")

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/snowild/gitlab-mcp'

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