Could not validate GitLab url. Got an unexpected answer

Hello everyone!
I’m Roberta and I’m new to the community!
I’m a DevOps engineer and thank you in advance for the help you will give me!
Today I tried to create the SonarQube - GitLab integration but to no avail.

Here’s some information about the environment I’m working on.

SonarQube GitLab
Community Edition v10.5.1 Community Edition v16.11.0
self-hosted self-hosted
Docker Docker
https://sonarqube.xxx.xxx.com/ https://gitlab.xxx.xxx.io/

I created an account on GitLab that I’m going to use for SonarQube and I followed the guide shown here.

After all i received the error:

Could not validate GitLab url. Got an unexpected answer.

My Server Web logs contains the following:

2024.05.03 15:17:51 DEBUG web[][o.s.a.c.g.GitlabApplicationClient] get projects : [https://gitlab.xxx.xxx.io/api/v4/projects]
2024.05.03 15:17:51 INFO  web[][o.s.a.c.g.GitlabApplicationClient] Gitlab API call to [https://gitlab.xxx.xxx.io/api/v4/projects] failed with error message : [Unexpected response code for CONNECT: 500]
java.io.IOException: Unexpected response code for CONNECT: 500
	at okhttp3.internal.connection.RealConnection.createTunnel(RealConnection.kt:483)
	at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.kt:262)
	at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:201)
	at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
	at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
	at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
	at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
	at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
	at org.sonar.alm.client.gitlab.GitlabApplicationClient.checkProjectAccess(GitlabApplicationClient.java:103)
	at org.sonar.alm.client.gitlab.GitlabApplicationClient.checkUrl(GitlabApplicationClient.java:86)
	at org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator.validate(GitlabGlobalSettingsValidator.java:53)
	at org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator.validate(GitlabGlobalSettingsValidator.java:46)
	at org.sonar.server.monitoring.devops.GitlabMetricsTask.validateGitlab(GitlabMetricsTask.java:58)
	at org.sonar.server.monitoring.devops.GitlabMetricsTask.run(GitlabMetricsTask.java:51)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.runAndReset(Unknown Source)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Finally, from inside my sonarqube container I executed

curl --header "PRIVATE-TOKEN: $mytoken" "https://gitlab.xxx.xxx.io/api/v4/projects"

and I received the correct JSON.

The only thing that came to mind is that the format of my GitLab’s URL could be a problem, because by trying with

  • https://gitlab.io/api/v4
    I don’t get the previous error, but:

Request was redirected, please provide the correct URL

  • https://gitlab.com/api/v4
    I don’t get the previous error, but:

Invalid personal access token

Can you help me, please?

Hi Roberta,

Welcome to the community!

This looks like a problem on the GitLab side. Did you check the logs over there?

 
Ann

Hi @ganncamp and thanks for your reply.

I investigated all logs of my GitLab instance but I don’t find anything.

I really don’t know what to do :frowning_face:

The last information I can give you is that my GitLab url point to a Kong gateway that forward request to GitLab, but I checked and no trace of errors even on Kong!

Hi,

Is it possible to bypass the stuff in the middle and connect directly from SonarQube to GitLab?

Do you have network folks who could help you on this?

 
Ann

Unfortunately it is not possible to bypass Kong.

As mentioned in my first post, from inside my SonarQube container I am able to call https://gitlab.xxx.xxx.io/api/v4/projects, so I suppose there is no network problems…

R.

Hi,

I’m sorry. I don’t know where else to tell you to look. SonarQube makes the call and receives an error. It’s not SonarQube making the error.

 
Ann

Hi,

thank you so much @ganncamp for your help! I will investigate on GitLab side and if I find a solution I’ll post it, maybe it will be useful to others.

Thank you!

R.

1 Like