#job #gitlab #artifact #trace #intervals #file-upload #jobs


Helper crate to build custom gitlab runners

9 releases

0.0.8 Jan 13, 2023
0.0.7 Oct 18, 2022
0.0.6 Aug 11, 2022
0.0.5 May 16, 2022
0.0.1 Sep 26, 2021
Download history 13/week @ 2023-08-13 2/week @ 2023-08-20 10/week @ 2023-08-27 24/week @ 2023-09-03 4/week @ 2023-09-10 4/week @ 2023-09-17 3/week @ 2023-09-24 5/week @ 2023-10-01 3/week @ 2023-10-08 4/week @ 2023-10-15 19/week @ 2023-10-22 18/week @ 2023-10-29 6/week @ 2023-11-05 4/week @ 2023-11-12 14/week @ 2023-11-19 34/week @ 2023-11-26

58 downloads per month


1.5K SLoC


A crate to help build custom gitlab runner implementations.

Implementing a custom runner

The overall idea is that this crate handles all interaction with the gitlab server and drives the executions while the the runner implementation focus on how to handle jobs from gitlab.

As the focus for an implementer of a custom runner is to implement the async JobHandler trait, which gets calle during job executation. An absolute minimal runner can be implement as such:

use gitlab_runner::{outputln, Runner, JobHandler, JobResult, Phase};
use std::path::PathBuf;

struct Run {}

impl JobHandler for Run {
      async fn step(&mut self, script: &[String], phase: Phase) -> JobResult {
          outputln!("Running script for phase {:?}", phase);
          for s in script {
            outputln!("Step: {}", s);

async fn main() {
    let mut runner = Runner::new(
        "runner token".to_owned(),
    runner.run(move | _job | async move { Ok(Run{})  }, 16).await.unwrap();

Gitlab runner registration

This crate does not support registering new runners with the gitlab server, so this has to be done by hand using the gitlab runner registration API.

The registration token can be retrieved from the runners section in the Gitlab administration area. With that token the runner can be register using a curl command like:

curl --request POST "https://GITLAB_URL/api/v4/runners"  \
  --form "description=My custom runner" \
  --form "run_untagged=false" \
  --form "tag_list=custom-gitlab-runner" \
  --form "token=REGISTRATION_TOKEN"

As a response to this command a new token for the registered runner will be provided, this token should be provided to the runner for it's gitlab connection.

One thing to key parameter provided here is run_untagged=false, which will make the runner only pickup jobs which matches its tag. This is important to prevent the runner from picking up "normal" jobs which it will not be able to process.


~427K SLoC