From a074343c587738006a71c8e47a574b453f7447d2 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 24 Aug 2021 08:06:28 +0200 Subject: [PATCH] SONAR-15312 Guide Jenkins users to configure pull/merge request discovery --- .../sonar-docs/src/pages/analysis/jenkins.md | 21 +- .../jenkins/MultiBranchPipelineStep.tsx | 66 ++- .../MultiBranchPipelineStep-test.tsx.snap | 392 +++++++++++++++++- .../resources/org/sonar/l10n/core.properties | 34 +- 4 files changed, 454 insertions(+), 59 deletions(-) diff --git a/server/sonar-docs/src/pages/analysis/jenkins.md b/server/sonar-docs/src/pages/analysis/jenkins.md index b669e82d546..630f148e6ad 100644 --- a/server/sonar-docs/src/pages/analysis/jenkins.md +++ b/server/sonar-docs/src/pages/analysis/jenkins.md @@ -114,23 +114,6 @@ For configuration examples, see the [SonarScanner for Jenkins](/analysis/scan/so ### Configuring Multibranch Pipeline jobs for Pull Request Decoration You need to configure your Multibranch Pipeline job correctly to avoid issues with Pull Request decoration. From your Multibranch Pipeline job in Jenkins, go to **Configure > Branch Sources > Behaviors**. -For Bitbucket Server and GitHub, under **Discover pull requests from origin**, make sure **The current pull request revision** is selected. - -For GitLab, under **Discover merge requests from origin**, make sure **Merging the merge request with the current target branch revision** is selected. - -## Detecting changed code in Pull Requests -SonarScanners need access to a Pull Request's target branch to detect code changes in the Pull Request. If you're using a Jenkins Pull Request discovery strategy that only fetches the Pull Request and doesn't merge with the target branch, the target branch is not fetched and is not available in the local git clone for the scanner to read. - -In this case, the code highlighted as “new” in the Pull Request may be inaccurate, and you’ll see the following warning in the scanner’s log: - -``` -File '[name]' was detected as changed but without having changed lines -``` - -To fix this, either change the discovery strategy or manually fetch the target branch before running the SonarScanner. For example: - -``` -git fetch +refs/heads/${CHANGE_TARGET}:refs/remotes/origin/${CHANGE_TARGET} -``` - +For Bitbucket and GitHub, under **Discover pull requests from origin**, make sure **The current pull request revision** is selected. +For GitLab, under **Discover merge requests from origin**, make sure **The current merge request revision** is selected. diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/MultiBranchPipelineStep.tsx b/server/sonar-web/src/main/js/components/tutorials/jenkins/MultiBranchPipelineStep.tsx index 01c46ed270e..c0ec55869e4 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/MultiBranchPipelineStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/MultiBranchPipelineStep.tsx @@ -27,6 +27,7 @@ import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../../types/alm-settings'; +import CodeSnippet from '../../common/CodeSnippet'; import LabelActionPair from '../components/LabelActionPair'; import LabelValuePair from '../components/LabelValuePair'; import SentenceWithHighlights from '../components/SentenceWithHighlights'; @@ -58,6 +59,10 @@ export default function MultiBranchPipelineStep(props: MultiBranchPipelineStepPr const { alm, almBinding, finished, open, projectBinding } = props; const workspaceId = extractBitbucketCloudWorkspaceId(almBinding); + const isGitLab = alm === AlmKeys.GitLab; + const isBitbucketServer = alm === AlmKeys.BitbucketServer; + const isBitbucketCloud = alm === AlmKeys.BitbucketCloud; + const isGitHub = alm === AlmKeys.GitHub; return (

diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/MultiBranchPipelineStep-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/MultiBranchPipelineStep-test.tsx.snap index 8364d95b281..5d667b9da78 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/MultiBranchPipelineStep-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/MultiBranchPipelineStep-test.tsx.snap @@ -72,9 +72,59 @@ exports[`should render correctly: content for bitbucket 1`] = `

  • - + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label + : + +
      +
    • + +
    • +
    • + +
    • +
    • + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label + : + +
        +
      • + +
      • +
      • + + +
      • +
      +
    • +
  • - + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label + : + +
      +
    • + +
    • +
    • + +
    • +
    • + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label + : + +
        +
      • + +
      • +
      • + + +
      • +
      +
    • +
  • - + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label + : + +
      +
    • + +
    • +
    • + +
    • +
    • + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label + : + +
        +
      • + +
      • +
      • + + +
      • +
      +
    • +
  • - + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label + : + +
      +
    • + +
    • +
    • + +
    • +
    • + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label + : + +
        +
      • + +
      • +
      • + + +
      • +
      +
    • +
  • - + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label + : + +
      +
    • + +
    • +
    • + +
    • +
    • + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label + : + +
        +
      • + +
      • +
      • + + +
      • +
      +
    • +
  • - + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label + : + +
      +
    • + +
    • +
    • + +
    • +
    • + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label + : + +
        +
      • + +
      • +
      • + + +
      • +
      +
    • +
  • - + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label + : + +
      +
    • + +
    • +
    • + +
    • +
    • + + onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label + : + +
        +
      • + +
      • +
      • + + +
      • +
      +
    • +