Browse Source

SONAR-15312 Guide Jenkins users to configure pull/merge request discovery

tags/9.1.0.47736
Wouter Admiraal 2 years ago
parent
commit
a074343c58

+ 2
- 19
server/sonar-docs/src/pages/analysis/jenkins.md View File

@@ -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.

+ 59
- 7
server/sonar-web/src/main/js/components/tutorials/jenkins/MultiBranchPipelineStep.tsx View File

@@ -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 (
<Step
@@ -82,7 +87,7 @@ export default function MultiBranchPipelineStep(props: MultiBranchPipelineStepPr
translationKey={`onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.${alm}`}
/>
<ul className="list-styled">
{alm === AlmKeys.BitbucketServer && (
{isBitbucketServer && (
<>
<li>
<LabelActionPair translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucket.server" />
@@ -112,7 +117,7 @@ export default function MultiBranchPipelineStep(props: MultiBranchPipelineStepPr
</li>
</>
)}
{alm === AlmKeys.BitbucketCloud && (
{isBitbucketCloud && (
<>
<li>
<LabelActionPair translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucketcloud.server" />
@@ -142,7 +147,7 @@ export default function MultiBranchPipelineStep(props: MultiBranchPipelineStepPr
</li>
</>
)}
{alm === AlmKeys.GitHub && (
{isGitHub && (
<>
<li>
<LabelActionPair translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.creds" />
@@ -161,7 +166,7 @@ export default function MultiBranchPipelineStep(props: MultiBranchPipelineStepPr
</li>
</>
)}
{alm === AlmKeys.GitLab && (
{isGitLab && (
<>
<li>
<LabelActionPair translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.gitlab.creds" />
@@ -175,9 +180,56 @@ export default function MultiBranchPipelineStep(props: MultiBranchPipelineStepPr
</>
)}
<li>
<LabelActionPair
translationKey={`onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.${alm}.behaviour`}
/>
<strong>
{translate(
'onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label'
)}
:
</strong>
<ul className="list-styled little-spacer-top abs-width-600">
<li>
<LabelActionPair
translationKey={`onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.${
isGitLab ? 'branches_mrs' : 'branches_prs'
}`}
/>
</li>
<li>
<LabelActionPair
translationKey={`onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.${
isGitLab ? 'discover_mrs' : 'discover_prs'
}`}
/>
</li>
<li>
<strong>
{translate(
'onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label'
)}
:
</strong>
<ul className="list-styled little-spacer-top">
<li>
<SentenceWithHighlights
highlightKeys={['add', 'ref_spec']}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour"
/>
</li>
<li>
<SentenceWithHighlights
highlightKeys={['ref_spec']}
translationKey={`onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.${
isGitLab ? 'set_mr_ref_specs' : 'set_pr_ref_specs'
}`}
/>
<CodeSnippet
isOneLine={true}
snippet="+refs/heads/*:refs/remotes/@{remote}/*"
/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p className="big-spacer-left padder-left">

+ 371
- 21
server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/MultiBranchPipelineStep-test.tsx.snap View File

@@ -72,9 +72,59 @@ exports[`should render correctly: content for bitbucket 1`] = `
</li>
</React.Fragment>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucket.behaviour"
/>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label
:
</strong>
<ul
className="list-styled little-spacer-top abs-width-600"
>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_prs"
/>
</li>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_prs"
/>
</li>
<li>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label
:
</strong>
<ul
className="list-styled little-spacer-top"
>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"add",
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour"
/>
</li>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_pr_ref_specs"
/>
<CodeSnippet
isOneLine={true}
snippet="+refs/heads/*:refs/remotes/@{remote}/*"
/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p
@@ -191,9 +241,59 @@ exports[`should render correctly: content for bitbucket cloud 1`] = `
</li>
</React.Fragment>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucketcloud.behaviour"
/>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label
:
</strong>
<ul
className="list-styled little-spacer-top abs-width-600"
>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_prs"
/>
</li>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_prs"
/>
</li>
<li>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label
:
</strong>
<ul
className="list-styled little-spacer-top"
>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"add",
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour"
/>
</li>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_pr_ref_specs"
/>
<CodeSnippet
isOneLine={true}
snippet="+refs/heads/*:refs/remotes/@{remote}/*"
/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p
@@ -308,9 +408,59 @@ exports[`should render correctly: content for bitbucket cloud, no binding 1`] =
</li>
</React.Fragment>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucketcloud.behaviour"
/>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label
:
</strong>
<ul
className="list-styled little-spacer-top abs-width-600"
>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_prs"
/>
</li>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_prs"
/>
</li>
<li>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label
:
</strong>
<ul
className="list-styled little-spacer-top"
>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"add",
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour"
/>
</li>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_pr_ref_specs"
/>
<CodeSnippet
isOneLine={true}
snippet="+refs/heads/*:refs/remotes/@{remote}/*"
/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p
@@ -425,9 +575,59 @@ exports[`should render correctly: content for bitbucket, no binding 1`] = `
</li>
</React.Fragment>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucket.behaviour"
/>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label
:
</strong>
<ul
className="list-styled little-spacer-top abs-width-600"
>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_prs"
/>
</li>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_prs"
/>
</li>
<li>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label
:
</strong>
<ul
className="list-styled little-spacer-top"
>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"add",
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour"
/>
</li>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_pr_ref_specs"
/>
<CodeSnippet
isOneLine={true}
snippet="+refs/heads/*:refs/remotes/@{remote}/*"
/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p
@@ -533,9 +733,59 @@ exports[`should render correctly: content for github 1`] = `
</li>
</React.Fragment>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.behaviour"
/>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label
:
</strong>
<ul
className="list-styled little-spacer-top abs-width-600"
>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_prs"
/>
</li>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_prs"
/>
</li>
<li>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label
:
</strong>
<ul
className="list-styled little-spacer-top"
>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"add",
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour"
/>
</li>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_pr_ref_specs"
/>
<CodeSnippet
isOneLine={true}
snippet="+refs/heads/*:refs/remotes/@{remote}/*"
/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p
@@ -640,9 +890,59 @@ exports[`should render correctly: content for github, no binding 1`] = `
</li>
</React.Fragment>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.behaviour"
/>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label
:
</strong>
<ul
className="list-styled little-spacer-top abs-width-600"
>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_prs"
/>
</li>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_prs"
/>
</li>
<li>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label
:
</strong>
<ul
className="list-styled little-spacer-top"
>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"add",
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour"
/>
</li>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_pr_ref_specs"
/>
<CodeSnippet
isOneLine={true}
snippet="+refs/heads/*:refs/remotes/@{remote}/*"
/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p
@@ -752,9 +1052,59 @@ exports[`should render correctly: content for gitlab 1`] = `
</li>
</React.Fragment>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.gitlab.behaviour"
/>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label
:
</strong>
<ul
className="list-styled little-spacer-top abs-width-600"
>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_mrs"
/>
</li>
<li>
<LabelActionPair
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_mrs"
/>
</li>
<li>
<strong>
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label
:
</strong>
<ul
className="list-styled little-spacer-top"
>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"add",
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour"
/>
</li>
<li>
<SentenceWithHighlights
highlightKeys={
Array [
"ref_spec",
]
}
translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_mr_ref_specs"
/>
<CodeSnippet
isOneLine={true}
snippet="+refs/heads/*:refs/remotes/@{remote}/*"
/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p

+ 22
- 12
sonar-core/src/main/resources/org/sonar/l10n/core.properties View File

@@ -3657,18 +3657,28 @@ onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.gitlab.owner.action
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.gitlab.repo.label=Projects
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.gitlab.repo.action=select your project.

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucket.behaviour.label=Behavior
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucket.behaviour.action=make sure "Exclude branches that are also filed as PRs" is selected.
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucketcloud.behaviour.label=Behavior
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.bitbucketcloud.behaviour.action=make sure "Exclude branches that are also filed as PRs" is selected.

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.behaviour.label=Behavior
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.behaviour.action=make sure "Exclude branches that are also filed as PRs" is selected.

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.gitlab.behaviour.label=Behaviours
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.gitlab.behaviour.action=make sure "Only branches that are not also filed as MRs" is selected.

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.leave_defaults=You can leave the other settings at the defaults.
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.label=Behaviors

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_prs.action=Exclude branches that are also filed as PRs
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_prs.label=Discover branches
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_mrs.action=Exclude branches that are also filed as MRs
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.branches_mrs.label=Discover branches

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_prs.action=The current pull request revision
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_prs.label=Discover pull requests from origin
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_mrs.action=The current merge request revision
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.discover_mrs.label=Discover merge requests from origin

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.label=Specify ref specs
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour.sentence=By default, this behavior is not active. If you do not see it, click on {add} to see the list of available behaviors, and select {ref_spec}.
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour.sentence.add=Add
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.add_behaviour.sentence.ref_spec=Specify ref specs
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_pr_ref_specs.sentence=In order to correctly compute new code for Pull Requests, the scanner will need the refs of the target branch. Make sure the {ref_spec} value will include any target branches (the default value should be enough). Example:
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_pr_ref_specs.sentence.ref_spec=Ref Spec
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_mr_ref_specs.sentence=In order to correctly compute new code for Merge Requests, the scanner will need the refs of the target branch. Make sure the {ref_spec} value will include any target branches (the default value should be enough). Example:
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.behaviors.ref_specs.set_mr_ref_specs.sentence.ref_spec=Ref Spec

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.leave_defaults=You can leave the other Branch Source settings at the defaults.

onboarding.tutorial.with.jenkins.multi_branch_pipeline.step3.sentence=Jump to the {tab} section and make sure the parameters are set as follows:
onboarding.tutorial.with.jenkins.multi_branch_pipeline.step3.sentence.tab=Build Configuration

Loading…
Cancel
Save