Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

SonarQube analysis was failing on PRs targeting develop with "Project not found" errors because the SonarQube configuration only supports the main branch.

Changes

  • Added if: github.base_ref == 'main' condition to the sonar job in .github/workflows/on-main.yml

This ensures the SonarQube job only executes when the PR base branch is main, preventing configuration mismatches for PRs targeting other branches.

jobs:
  sonar:
    name: Tests & SonarQube
    if: github.base_ref == 'main'
    uses: ./.github/workflows/sonar.yml
    secrets:
      SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Original prompt

Problem

The workflow on-main.yml is executing on pull requests that target the develop branch, causing SonarQube analysis to run when it shouldn't. This results in failures because the SonarQube configuration is only set up for the main branch.

The job ID 61272200807 from PR #20 (which targets develop) failed with:

ERROR Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties

This happens because SonarQube should only run on PRs targeting main, not develop.

Solution

Add a conditional check to the sonar job in .github/workflows/on-main.yml to ensure it only executes when the base branch of the pull request is actually main.

Required Changes

Modify .github/workflows/on-main.yml to add the condition if: github.base_ref == 'main' to the sonar job:

name: Main CI

on:
  workflow_dispatch:
  pull_request:
    branches:
      - main
    types: [opened, synchronize, reopened]

jobs:
  sonar:
    name: Tests & SonarQube
    # Solo ejecutar si la base del PR es realmente 'main'
    if: github.base_ref == 'main'
    uses: ./.github/workflows/sonar.yml
    secrets:
      SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

This ensures that even if the workflow is triggered, the SonarQube job will only run when the PR is actually targeting the main branch, preventing it from running on PRs to develop.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: altaskur <105789412+altaskur@users.noreply.github.com>
Copilot AI changed the title [WIP] Add condition to SonarQube job for main branch only Add base ref check to prevent SonarQube job on non-main PRs Jan 23, 2026
Copilot AI requested a review from altaskur January 23, 2026 13:40
@altaskur altaskur marked this pull request as ready for review January 23, 2026 13:41
@sonarqubecloud
Copy link

@altaskur altaskur merged commit 7aa57ad into main Jan 23, 2026
2 checks passed
@altaskur altaskur deleted the copilot/fix-sonarqube-analysis-condition branch January 23, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants