You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins执行SonarQube任务报错及项目关联配置咨询

Fixing SonarQube + Jenkins: "Task Does Not Exist" & Project Configuration Issues

Hey there, let’s work through this SonarQube + Jenkins problem step by step— I’ve dealt with similar headaches before, so I know exactly where to start.

1. First: Fix the "Task 'my-task' does not exist" Error

This error almost always happens because you’re using the project display name in Jenkins instead of SonarQube’s unique project key. SonarQube uses keys to identify projects, not the friendly name you set when creating it.

  • Log into your SonarQube server, find the project you created
  • Head to the project details page (or project settings) and grab the Project Key— it might look like my-task-key (could be different from the name you typed)
  • Make sure Jenkins is configured to use this key, not the display name, when referencing the task

2. Linking Your Actual Project to SonarQube & Setting Scan Paths

Here’s a common misconception: you don’t need to manually link your server’s project path in SonarQube’s backend. The scan path is controlled by your build command (like Maven) when you run the analysis.

When you created the project in SonarQube, it should’ve generated a sample analysis command (for Maven, it looks like this):

mvn sonar:sonar \
  -Dsonar.projectKey=your-project-key \
  -Dsonar.projectName="Your Project Name" \
  -Dsonar.host.url=http://your-sonarqube-server:9000 \
  -Dsonar.token=your-auth-token

To scan your project at /home/{user}/live/{sitename}/htdocs, just run this command from that directory— SonarQube will automatically scan all code there.

If you need to narrow down the scan to specific folders (like only src or htdocs), add this parameter:

-Dsonar.sources=src,htdocs # Separate multiple paths with commas

3. Configuring SonarQube in Jenkins Build Steps

Since your project uses Maven, let’s cover two straightforward ways to set this up:

Option 1: Use Maven Build Step with SonarQube Params

  • In your Jenkins project configuration, go to the Build section and add an Invoke top-level Maven targets step
  • In the Goals field, enter:
    clean verify sonar:sonar
    
  • In the Properties section, add these key-value pairs (replace with your actual values):
    sonar.projectKey=your-project-key-from-sonarqube
    sonar.projectName=Your Project’s Display Name
    sonar.host.url=http://localhost:9000 # Since SonarQube is on the same server, localhost works
    sonar.token=your-sonarqube-auth-token # Generate this in SonarQube’s user settings
    sonar.projectBaseDir=/home/{user}/live/{sitename}/htdocs # Tells Maven where your project lives
    

Option 2: Use the SonarQube Scanner Plugin

If you have the SonarQube Scanner plugin installed in Jenkins:

  • Add an Execute SonarQube Scanner build step to your project
  • In the Analysis properties box, paste these lines (adjust values as needed):
    sonar.projectKey=your-project-key
    sonar.projectName=Your Project Name
    sonar.host.url=http://localhost:9000
    sonar.token=your-auth-token
    sonar.projectBaseDir=/home/{user}/live/{sitename}/htdocs
    sonar.sources=. # Scans all files in the project base dir; replace with specific paths if needed
    

Quick Checks to Avoid Headaches Later

  • Make sure the Jenkins user (usually jenkins) has permission to access /home/{user}/live/{sitename}/htdocs— use chown or chmod to adjust permissions if needed
  • The SonarQube token you use should have project analysis permissions (check this in SonarQube’s project settings)
  • If you’re still stuck, run this command from your project directory on the server to list all valid SonarQube projects:
    mvn sonar:list -Dsonar.host.url=http://localhost:9000 -Dsonar.token=your-token
    
    This will show you all projects SonarQube recognizes— confirm your project key is in the list.

内容的提问来源于stack exchange,提问作者ThurstonLevi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:32:29