I am trying to build a CI/CD pipeline( GCP used) but I am getting struck. I have followed the steps and made the settings as explained here:
However, the build is failing at sonar quality check stage on Jenkins.
jenkins code:
pipeline{
agent any
environment{
VERSION = "${env.BUILD_ID}"
}
stages{
stage("sonar quality check"){
agent {
docker {
image 'openjdk:11'
}
}
steps{
script{
withSonarQubeEnv(credentialsId: 'sonar-token') {
sh 'chmod +x gradlew'
sh './gradlew sonarqube'
sh 'java -version'
}
timeout(time: 1, unit: 'HOURS') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
}
}
Jenkins console output :
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 1001:1002 -w /var/lib/jenkins/workspace/javaapplication@2 -v /var/lib/jenkins/workspace/javaapplication@2:/var/lib/jenkins/workspace/javaapplication@2:rw,z -v /var/lib/jenkins/workspace/javaapplication@2@tmp:/var/lib/jenkins/workspace/javaapplication@2@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** openjdk:11 cat
$ docker top 2a18574dd0cbc94634f9a16aa6e5ddcde66c9ffb453474c92bb0a4f6d2b9e32d -eo pid,comm
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: sonarserver
[Pipeline] {
[Pipeline] sh
+ chmod +x gradlew
[Pipeline] sh
+ ./gradlew sonarqube
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :compileTestJava UP-TO-DATE
> Task :sonarqube FAILED
SonarQube server [http://34.125.91.25:9000] can not be reached
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sonarqube'.
> Unable to execute SonarScanner analysis
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 19s
4 actionable tasks: 1 executed, 3 up-to-date
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // script
[Pipeline] }
$ docker stop --time=1 2a18574dd0cbc94634f9a16aa6e5ddcde66c9ffb453474c92bb0a4f6d2b9e32d
$ docker rm -f 2a18574dd0cbc94634f9a16aa6e5ddcde66c9ffb453474c92bb0a4f6d2b9e32d
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
That was part of the console last time too. But before that was the error about not being able to contact the SonarQube server. You’re going to need to fix that first.
Hi Ann, thanks for the input I have fixed that error and double checked everything. Is there anything else, you would like to suggest, I am still getting the same output
@ganncamp Facing the exact same issue, I was able to curl & ping from the Jenkins server to sonarqube server. I am exactly using the same code which Prashant is using above.
Please let me know if you need any other additional info ?