This tutorial help to convert gitlab raw log into html color view. The gitlab ci/cd are generating logs for each jobs. You can view color view logs using gitlab view.
I have asked question into the https://stackoverflow.com/questions/66149229/convert-gitlab-raw-logs-into-html-color-view-using-php as well, but did not get answer from any body So I have shared my solution that can be helpful.
I am creating a angularjs ui where user can see gitlab job logs, So we have created a rest call that ll return raw logs as text and render into html UI.
The gitlab v4 api is providing a rest end point to get a log (trace) of a specific job of a project.
GET /projects/:id/jobs/:job_id/trace
Where id
is the project id and job_id
is the job id.
I have created a Laravel api that will return html format of raw git job logs, I have taken this job logs but in git raw api there is ANSI codes that need to convert into HTML5 format.
The trace url would be –
https://gitlab.com/api/v4/projects/7909770/jobs/101128183/trace
When we access above api call, We ll get the raw logs with ansi characters, that ll hold color value;
I am using laravel 7 framework, so i ll use sensiolabs/ansi-to-html package that help to convert ANSI character into html.
Let’s install packages –composer require sensiolabs/ansi-to-html
We have installed package into the application, open the testController.php
file and added below code into the top of the file –
use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
Created the instance into the controller constructor method :
protected $ansihtml; public function __construct() { $this->ansihtml = new AnsiToHtmlConverter(); }
Let’s call convert method over the gitlab raw logs.
public function jobLogs($job_id, $pipeline_id) { $ansi = $this->getGitlabLogs($project_id, $job_id); $html = $this->ansihtml->convert($ansi); return html; }
When you render above response into html file, You will get below view –
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More