i have jenkins config for setting up integrate from jenkins to sonarqube `
// Stage to check SonarQube task status
stage('Check SonarQube Task Status') {
steps {
script {
// Poll the SonarQube API for task status
def taskId = getSonarQubeTaskId() // Function to fetch the task ID from the previous stage
def taskStatus = getSonarQubeTaskStatus(taskId) // Function to fetch task status
// If the task status is not 'SUCCESS', abort the pipeline
if (taskStatus != 'SUCCESS') {
error "SonarQube scan failed. Aborting pipeline!"
} else {
echo "SonarQube scan passed. Continuing pipeline."
}
}
}
// Function to get the SonarQube task status using the API
def getSonarQubeTaskStatus(taskId) {
def sonarApiUrl = "${env.SONARQUBE_SERVER}/api/ce/task?id=${taskId}"
def response = httpRequest(url: sonarApiUrl, authentication: 'sonar-token') // Use your authentication method here
def jsonResponse = readJSON text: response
return jsonResponse.task.status
}
I have tried to get status from my sonarqube on jenkins. but i cannot get that... when i check on my sonarqube status my code already passed
but when i check on jenkins i got error ERROR: Failed to extract SonarQube Task ID from scanner output Finished: FAILURE
my code is using golang and deploy on ec2
how to fix this issue ?
my expecting is my code can running the others process such as
stage('Build Docker Image') {
steps {
sh 'docker build -t $GITLAB_REGISTRY/$IMAGE_NAME:latest .'
}
}
stage('Login to GitLab Registry') {
steps {}
how to fix this issue ?
Can you try below config. it may be helpful as i know.
This is for extracting the taskid correctly
def getSonarQubeTaskStatus(taskId) {
def sonarApiUrl = "${env.SONARQUBE_SERVER}/api/ce/task?id=${taskId}"
echo "Fetching SonarQube task status from: ${sonarApiUrl}"
def response = httpRequest(url: sonarApiUrl, authentication: 'sonar-token')
echo "SonarQube API Response: ${response.content}"
def jsonResponse = readJSON text: response.content
return jsonResponse.task.status
}
and below is for checking the task status.
def getSonarQubeTaskStatus(taskId) {
def sonarApiUrl = "${env.SONARQUBE_SERVER}/api/ce/task?id=${taskId}"
echo "Fetching SonarQube task status from: ${sonarApiUrl}"
def response = httpRequest(url: sonarApiUrl, authentication: 'sonar-token')
echo "SonarQube API Response: ${response.content}"
def jsonResponse = readJSON text: response.content
return jsonResponse.task.status
}