Connect Any Git Server
This page explains how to add a project hosted on a private Git server.
Overview
Semaphore can work with repositories hosted on any privately-run Git server via SSH.
Before you start, ensure you have SSH access to the machine running the Git service. Then, take note of the following parameters:
- public IP or domain name of your Git server, e.g.
my-git-server.org
) - user running the Git service, e.g.
git
- home directory for the user running the git service, e.g.
/home/git
- directory containing the repositories, e.g.
/srv/git
How to create a bare repository
This section provides a guide on creating a new repository to practice to anyone new to the world of private Git servers. You can skip this section if you're familiar with managing Git servers.
To create a new repository:
-
Connect to the server running the Git service, e.g.
ssh git@example.com
-
Change to the directory where the repositories are hosted, e.g.
cd /srv/git
-
Create a new bare repository, e.g.
git init --bare my-repo.git
-
On a different terminal, clone the remote repository to your local machine, e.g.
git clone ssh://git@my-git-server.org/srv/git/my-repo.git
-
Once cloned, ensure the repository has at least one commit (so it is not empty), e.g.
cd my-repo
echo "# This is a test" > README.md
git add README.md
git commit -m initial commit
git push origin main
How to create a project
To connect with this method, press the Create new button.
-
Select the Generic Git
Show me
-
Type the SSH URL used to clone the repository, e.g.
ssh://git@my-git-server.org/srv/git/my-repo.git
-
Optionally, change the name of the project
Show me
-
Copy the public SSH key shown on screen
Show me
-
SSH into the Git server add the SSH key copied in the previous step to
$HOME/.ssh/authorized_keys
(relative to the user that runs the Git service) and press Continue -
Back in Sempahore, press the Generate Script button
Show me
-
In the Git server, go into the directory containing the bare repository (e.g.
/srv/git/my-repo.git
) -
Create the post-receive script in the
hooks
directory, pay attention to:- Filename:
post-receive
- Contents: the script copied in Step 6
- Owner: check that the script is owned by the same user running the Git service, e.g.
chown git:git post-receive
- Permission to execute:
chmod a+x post-receive
- Prerequisite packages: curl
- Filename:
-
Semaphore will wait for the post-receive hook to be executed. To do that, commit and push a new/modified file into the repository.
-
Back in Semaphore, once the Git hook is executed, press Configure workflow
-
Select the default agent for this project and press Continue
Show me
-
Select a starter workflow. You may also Customize or Design from scratch
Show me
Troubleshooting guide
If your repositories aren't showing in Semaphore or changes are not triggering new workflows, check the connection between Semaphore and your Git server.
Verify deploy key and webhook
-
Open your project
-
Go to the Settings, then Repository
-
Check the status of Deploy Key and Webhook. Press Regenerate if any of parameters are marked with error:
- If regenerating a deployment key, you must update the
$HOME/.ssh/authorized_keys
(see Step 4 of How to create a project) - If regenerating the webhook, update the
endpoint
value in thepost-receive
hook (see Step 8 of How to create a project)
- If regenerating a deployment key, you must update the
Reconnecting moved or renamed projects
There are several actions that can break the connection between the Git server and Semaphore. For example:
- moving the repository to a different location
- renaming the repository
When this happens, you must update the URL of the repository in Semaphore. To do this:
- Open your project settings
- Type the new repository URL
- Press Change
After changing the URL, double-check the status of the deploy key and webhook.
File semaphore.yml is not available
You might see the following error message when trying to run workflows on Semaphore:
semaphore.yml ERROR:
Error: {"File '.semaphore/semaphore.yml' is not available", "Not Found"}
This means that Semaphore can't fetch the .semaphore/semaphore.yml
file from the repository. There are two reasons why this might happen:
- The file doesn't exist on your repository: double check to make sure that the Semaphore YAML file actually exists
- Repository is disconnected from Semaphore: follow the steps previously described