Suche
  • Markus Stahl

Building a simple GitLab Dashboard with Robot Framework

In this article we will demonstrate Robot Frameworkin a small RPA example: we will "misuse" its reporting for a simple quick & dirty dashboard for GitLab pipelines. An implementation of this project is available at our GitHub from Deutsche Post Adress.



Ingredients:

If you do not know DataDriver, yet, the main task might be confusing containing only variables (line 25):



The magic hides in line 12: DataDriver generates a task for each line of projects.csv file. Each column of a line in this csv file will be available as variable:



DataDriver will generate 6 tasks from this file, each with parameters project, id and branch. The generated tasks are based on the Task Template which is Get pipeline status (line 15). Get pipeline status is the main keyword and its implementation starts at line 28.


What does line 25 do, you might wonder. ${project} : ${branch} will be the task's name by which you will identify it in your final report. The remaining values are parameters passed to the template keyword matching the arguments in line 29.


The remaining keywords not shown in this screenshot are calls to GitLab REST API using robotframework-requests library. In line 32 and 33 additional information from the pipeline is added the robot report. Very important is tagging the status of the pipeline itself, which might be not only successful or failed, but also cancelled, pending or running.


Line 34 checks whether a pipeline passed or failed: A task is only successful if its last pipeline was a successful, too. But what about "neutral" pipelines such as cancelled, pending or running? They would be marked as failures, too. But you could categorize them as "non-critical" tasks (using the -n option) meaning those will still be marked as failure, but won't let the robot report be marked as failure:


robot -n pending -n skipped -n running dashboard.robot

Last but not least, you must add an API token and url to your gitlab server. Never push your API token in version control repository! The token provides access to your repositories, which should be handled sensitive. You can pass those parameters as variables when calling robot. The full statement lookslike this:


robot -n pending -n skipped -n running -v GITLAB_URL:<url_to_gitlab_projects> -v API_TOKEN:<your_generated_api_token> dashboard.robot

In the end you can set up a job in your favourite job scheduling tool running this robot task frequently. If a failed pipeline is among the checked pipelines, the job will report it.



If you are into ChatOps you can post robot reports in your monitoring channels notifying users, when pipelines break.


Do you have small usecases for using Robot Framework as tool other than for test automation?

262 Ansichten0 Kommentare

Aktuelle Beiträge

Alle ansehen