How to integrate Gitlab Git repository into Redmine

Deutsch English

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

create_redmine_git_dir.sh
mkdir redmine_git
docker-compose.yml
services:
  redmine:
    # ...
    volumes:
      # ...
      - './redmine_git:/git'

Cloning a Gitlab repository into Redmine

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

repository_clone_url.txt
https://Redmine:[email protected]/myuser/MyProject.git
mirror_clone_repository.sh
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:

setup-git-fetch.sh
#!/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:

run_setup_git_fetch.sh
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.


Check out similar posts by category: Redmine, Git