def METHOD_NAME(project_name, pipeline_id):
    """
    Retrieves the list of failed jobs for a given pipeline id in a given project.
    """
    gitlab = Gitlab(project_name=project_name, api_token=get_gitlab_token())
    # gitlab.all_jobs yields a generator, it needs to be converted to a list to be able to
    # go through it twice
    jobs = list(gitlab.all_jobs(pipeline_id))
    # Get instances of failed jobs
    failed_jobs = {job["name"]: [] for job in jobs if job["status"] == "failed"}
    # Group jobs per name
    for job in jobs:
        if job["name"] in failed_jobs:
            failed_jobs[job["name"]].append(job)
    # There, we now have the following map:
    # job name -> list of jobs with that name, including at least one failed job
    final_failed_jobs = []
    for job_name, jobs in failed_jobs.items():
        # We sort each list per creation date
        jobs.sort(key=lambda x: x["created_at"])
        # We truncate the job name to increase readability
        job_name = truncate_job_name(job_name)
        # Check the final job in the list: it contains the current status of the job
        # This excludes jobs that were retried and succeeded
        failure_type, failure_reason = get_job_failure_context(gitlab.job_log(jobs[-1]["id"]))
        final_status = {
            "name": job_name,
            "id": jobs[-1]["id"],
            "stage": jobs[-1]["stage"],
            "status": jobs[-1]["status"],
            "tag_list": jobs[-1]["tag_list"],
            "allow_failure": jobs[-1]["allow_failure"],
            "url": jobs[-1]["web_url"],
            "retry_summary": [job["status"] for job in jobs],
            "failure_type": failure_type,
            "failure_reason": failure_reason,
        }
        # Also exclude jobs allowed to fail
        if final_status["status"] == "failed" and not final_status["allow_failure"]:
            final_failed_jobs.append(final_status)
    return final_failed_jobs