admin管理员组

文章数量:1294707

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 ?

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 ?

Share Improve this question edited Feb 12 at 11:48 Reporter 3,9485 gold badges35 silver badges49 bronze badges asked Feb 12 at 11:43 jujil lololojujil lololo 32 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

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

}

Check Plugins: Ensure Jenkins has the SonarQube Scanner plugin installed.

Configure SonarQube: Add SonarQube server details in Jenkins (Manage Jenkins > Configure System).

Scanner Setup: Install the SonarQube Scanner in Jenkins (Global Tool Configuration).

Add Step: In your Jenkins job, add a "Execute SonarQube Scanner" build step.

Check Logs: If it fails, check Jenkins logs for errors.

本文标签: Issueing when integrate jenkins with sonarqube scannerStack Overflow