fobius
fobius

Reputation: 295

Gitea and Jenkins setup in Docker

I'm trying to get a setup where Gitea and Jenkins are running in separate Docker containers and set up a simple pipeline.

The issue I'm running into is connecting Jenkins to Gitea. In my setup, Gitea is listening for SSH on port 22 in the container, and I map this to port 3001 on my localhost (for testing purposes for now).

From the create new pipeline interface, I'm asked to provide the SSH url to the Gitea repo. I did provide this as:

git@localhost:3001/repo/project.git

But it seemed Jenkins was unable to connect saying that I need a valid URL. I have already added the Jenkins generated key to my Git user profile.

I then tried to do a git clone from my localhost, so I generated a pair of keys, added the public key to the same Git profile, and then executed the command

git clone ssh://git@localhost:3001/repo/project.git

However the result was:

Cloning into 'project'...
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

So I'm not really sure what I'm missing. I did add my local machine generated key to GitHub and was able to clone fine from there, so am pretty sure this is related to Gitea in the Docker environment.

I already verified that the Jenkins container can see the Gitea container and that they are joined on the same network.

What am I missing here so that I can git clone from Gitea running in Docker ? I believe this would be the key to solving the Jenkins issue as well.

Thanks

Upvotes: 0

Views: 2884

Answers (1)

KMZ
KMZ

Reputation: 536

It looks like the URL you gave Jenkins (git@localhost:3001/repo/project.git) implies Jenkins' localhost, i.e. the container it runs in, but not the docker host localhost, i.e. the server whose port 3001 gets forwarded to Gitea container port 22.

Try using HTTP-based git repo URL first, e.g. http://:3000/username/mypetproject, provided that you also forwarded Gitea's UI port 3000 to the same port on your docker host.

I have a similar setup working: Gitea and Jenkins both run in their own containers on the same network, the whole thing is managed by docker-compose. Gitea container exports port 3000 as host port 3000, and port 22 as 22022. Also, Gitea is hosted in the sub-path /gitea/: I have a bunch of other things in the compose file and wanted to avoid having to explicitly specify ports, so I added an nginx instance as a reverse proxy that routes /jenkins/* requests to Jenkins' container, and /gitea/* requests to Gitea's.

In Jenkins job settings I use http://<hostname>/gitea/username/repo.git as a repo URL. <hostname> is obviously the name of the docker host.

One last thing: try docker execing into a running Gitea container and cloning the repo locally using port 22 (basically same thing you tried from the localhost). If this works successfully, you can be reasonably sure that Gitea is not at fault, and you should be looking into your networking/port-forwarding setup.

Upvotes: 1

Related Questions