With a simple gradle project using jenkins for CI and withSonarQubeEnv method to inject sonar url and token information, i have this error message since gradle 8.8 :
Caching disabled for task ':sonar' because:
Build cache is disabled
Task ':sonar' is not up-to-date because:
Task has not declared any outputs despite executing actions.
User cache: /root/.sonar/cache
SonarQube server [http://localhost:9000] can not be reached
It seems that sonar.host.url and sonar.login are not anymore set by sonar scanner jenkins plugin.
It can be easily reproduced by doing a sonarqube analysis on jenkins pipeline with gradle 8.8.
Anyone is experiencing the same issue ? Any help would be welcome
Could you please share more info about the gradle build configuration?
Are you using build cache? In that case, can you try to see if there is any improvement when enabling or disabling the caching explicitly? (see Gradle 8.8 release-notes | build-cache-changes)
It would help significantly if you could share the relevant configuration.
I’m involving experts with the Jenkins scanner to investigate on their side and gather more insight.
My jenkins pipeline use kubernetes plugin so the entire pipeline runs in an ephemeral pod without any cache so if i change gradle build-cache it won’t have any effects.
The withSonarQubeEnv step should populate some environment variables, that the SonarScanner for Gradle (well, in fact, any scanner) should see and use.
Can you try to investigate if those variables are correctly passed, changing your pipeline to something like:
stage('QA') {
withSonarQubeEnv('sonarqube') {
sh 'echo "Sonar Host is $SONAR_HOST_URL"'
sh './gradlew sonar -Dsonar.projectKey=mykey -Dsonar.projectName=myproject'
}
}
Assuming the variable is correctly set, and since Gradle uses a daemon, maybe this is what is causing the issue. Maybe the env variables are not visible to the Gradle process because it is reusing a previous daemon. I quickly checked Gradle 8.8 release notes to find a change around the daemon and env variables, but could not find anything.
Still, to verify this idea, you could try to disable the daemon:
sh './gradlew sonar --no-daemon -Dsonar.projectKey=mykey -Dsonar.projectName=myproject'
Might be worth reporting it to Gradle, yes. I initially thought this was an expected behavior (the daemon would capture all env variables on its first start, then the subsequent runs would not see updated variables), but apparently, they do have a way to “see” updated variables. But it seems to have some issues, like: Environment Variable mutation not working on IBM AIX · Issue #12905 · gradle/gradle · GitHub
Even if it’s a Gradle issue, the fact is that the sonarqube jenkins plugin won’t be able to be used with gradle 8.8+, so plugin maintainer will have to handle this case.