How to integrate Gitlab Git repository into Redmine

Setting up the Redmine Git infrastructure

Redmine Git Project Access Token

Gitlab Copy Access Token

The following is based on Redmine docker-compose config with Traefik & Let’s Encrypt

mkdir redmine_git
services:
  redmine:
    # ...
    volumes:
      # ...
      - './redmine_git:/git'

Cloning a Gitlab repository into Redmine

Repeat this for every repository you want to integrate into Redmine.

https://Redmine:[email protected]/myuser/MyProject.git
cd redmine_git
git clone --mirror https://Redmine:[email protected]/myuser/MyProject.git

Redmine Settings Repositories

Redmine Create New Repository

Setup automatic repository fetch

Redmine currently does not support fetching repositories automatically. You can set up a cronjob to fetch repositories every 5 minutes.

I recommend to use SystemD timers for this, as they are more reliable and generally more flexible than cronjobs.

In the directory where redmine_git resides, create a new file setup-git-fetch.sh, which sets up the fetch script and timer:

#!/bin/bash
export NAME=$(basename $(pwd))-gitfetch

cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'cd redmine_git && for i in *; do [ -d "\$i" ] && cd "\$i" && git fetch --all; cd ..; done'
WorkingDirectory=$(pwd)
EOF

cat >/etc/systemd/system/${NAME}.timer <<EOF
[Unit]
Description=${NAME} timer

[Timer]
OnCalendar=*:0/2
Persistent=true

[Install]
WantedBy=timers.target
EOF

# Enable and start service
systemctl enable --now ${NAME}.timer

Run that script from the directory where redmine_git resides:

sudo bash setup-git-fetch.sh

This script sets up a SystemD service and timer that fetches all repositories in redmine_git every 2 minutes.