import org.sonar.api.ce.posttask.Project;
import org.sonar.api.ce.posttask.QualityGate;
import org.sonar.api.ce.posttask.ScannerContext;
-import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
private final QualityGateStatusHolder qualityGateStatusHolder;
private final PostProjectAnalysisTask[] postProjectAnalysisTasks;
private final BatchReportReader reportReader;
- private final System2 system2;
/**
* Constructor used by Pico when there is no {@link PostProjectAnalysisTask} in the container.
*/
- public PostProjectAnalysisTasksExecutor(org.sonar.ce.task.CeTask ceTask,
- AnalysisMetadataHolder analysisMetadataHolder,
- QualityGateHolder qualityGateHolder, QualityGateStatusHolder qualityGateStatusHolder,
- BatchReportReader reportReader, System2 system2) {
- this(ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, system2, null);
+ public PostProjectAnalysisTasksExecutor(org.sonar.ce.task.CeTask ceTask, AnalysisMetadataHolder analysisMetadataHolder,
+ QualityGateHolder qualityGateHolder, QualityGateStatusHolder qualityGateStatusHolder, BatchReportReader reportReader) {
+ this(ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, null);
}
- public PostProjectAnalysisTasksExecutor(org.sonar.ce.task.CeTask ceTask,
- AnalysisMetadataHolder analysisMetadataHolder,
- QualityGateHolder qualityGateHolder, QualityGateStatusHolder qualityGateStatusHolder,
- BatchReportReader reportReader, System2 system2,
- @Nullable PostProjectAnalysisTask[] postProjectAnalysisTasks) {
+ public PostProjectAnalysisTasksExecutor(org.sonar.ce.task.CeTask ceTask, AnalysisMetadataHolder analysisMetadataHolder, QualityGateHolder qualityGateHolder,
+ QualityGateStatusHolder qualityGateStatusHolder, BatchReportReader reportReader, @Nullable PostProjectAnalysisTask[] postProjectAnalysisTasks) {
this.analysisMetadataHolder = analysisMetadataHolder;
this.qualityGateHolder = qualityGateHolder;
this.qualityGateStatusHolder = qualityGateStatusHolder;
this.ceTask = ceTask;
this.reportReader = reportReader;
this.postProjectAnalysisTasks = postProjectAnalysisTasks == null ? NO_POST_PROJECT_ANALYSIS_TASKS : postProjectAnalysisTasks;
- this.system2 = system2;
}
@Override
new CeTaskImpl(this.ceTask.getUuid(), status),
createProject(this.ceTask),
getAnalysis().orElse(null),
- getAnalysis().map(a -> a.getDate().getTime()).orElse(system2.now()),
ScannerContextImpl.from(reportReader.readContextProperties()),
status == SUCCESS ? createQualityGate() : null,
createBranch(),
}
private Optional<Analysis> getAnalysis() {
- Long analysisDate = getAnalysisDate();
-
- if (analysisDate != null) {
- return of(new AnalysisImpl(analysisMetadataHolder.getUuid(), analysisDate, analysisMetadataHolder.getScmRevision()));
+ if (analysisMetadataHolder.hasAnalysisDateBeenSet()) {
+ return of(new AnalysisImpl(analysisMetadataHolder.getUuid(), analysisMetadataHolder.getAnalysisDate(), analysisMetadataHolder.getScmRevision()));
}
return empty();
}
.orElseThrow(() -> new IllegalStateException("Report processed for a task of a deleted component"));
}
- @CheckForNull
- private Long getAnalysisDate() {
- if (this.analysisMetadataHolder.hasAnalysisDateBeenSet()) {
- return this.analysisMetadataHolder.getAnalysisDate();
- }
- return null;
- }
-
@CheckForNull
private QualityGate createQualityGate() {
Optional<org.sonar.ce.task.projectanalysis.qualitygate.QualityGate> qualityGateOptional = this.qualityGateHolder.getQualityGate();
private static class ProjectAnalysisImpl implements PostProjectAnalysisTask.ProjectAnalysis {
private final CeTask ceTask;
private final Project project;
- private final long date;
private final ScannerContext scannerContext;
@Nullable
private final QualityGate qualityGate;
private final String scmRevisionId;
private ProjectAnalysisImpl(CeTask ceTask, Project project,
- @Nullable Analysis analysis, long date,
- ScannerContext scannerContext, @Nullable QualityGate qualityGate, @Nullable Branch branch, String scmRevisionId) {
+ @Nullable Analysis analysis, ScannerContext scannerContext, @Nullable QualityGate qualityGate, @Nullable Branch branch, String scmRevisionId) {
this.ceTask = requireNonNull(ceTask, "ceTask can not be null");
this.project = requireNonNull(project, "project can not be null");
this.analysis = analysis;
- this.date = date;
this.scannerContext = requireNonNull(scannerContext, "scannerContext can not be null");
this.qualityGate = qualityGate;
this.branch = branch;
return qualityGate;
}
- @Override
- public Date getDate() {
- return new Date(date);
- }
-
- @Override
- public Optional<Date> getAnalysisDate() {
- return analysis == null ? empty() : ofNullable(analysis.getDate());
- }
-
@Override
public Optional<Analysis> getAnalysis() {
return ofNullable(analysis);
return "ProjectAnalysis{" +
"ceTask=" + ceTask +
", project=" + project +
- ", date=" + date +
", scannerContext=" + scannerContext +
", qualityGate=" + qualityGate +
", analysis=" + analysis +
import org.mockito.InOrder;
import org.sonar.api.ce.posttask.PostProjectAnalysisTask;
import org.sonar.api.ce.posttask.Project;
-import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.ce.task.CeTask;
@Rule
public LogTester logTester = new LogTester();
- private final System2 system2 = mock(System2.class);
private final ArgumentCaptor<PostProjectAnalysisTask.Context> taskContextCaptor = ArgumentCaptor.forClass(PostProjectAnalysisTask.Context.class);
private final CeTask.Component component = new CeTask.Component("component uuid", "component key", "component name");
private final CeTask ceTask = new CeTask.Builder()
private final PostProjectAnalysisTask postProjectAnalysisTask = newPostProjectAnalysisTask("PT1");
private final PostProjectAnalysisTasksExecutor underTest = new PostProjectAnalysisTasksExecutor(
ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder,
- reportReader, system2,
- new PostProjectAnalysisTask[] {postProjectAnalysisTask});
+ reportReader, new PostProjectAnalysisTask[] {postProjectAnalysisTask});
@Before
public void setUp() {
@Test
@UseDataProvider("booleanValues")
public void does_not_fail_when_there_is_no_PostProjectAnalysisTasksExecutor(boolean allStepsExecuted) {
- new PostProjectAnalysisTasksExecutor(ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, system2)
+ new PostProjectAnalysisTasksExecutor(ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader)
.finished(allStepsExecuted);
}
new PostProjectAnalysisTasksExecutor(
ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader,
- system2, new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2})
+ new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2})
.finished(allStepsExecuted);
inOrder.verify(postProjectAnalysisTask1).finished(taskContextCaptor.capture());
verify(postProjectAnalysisTask).finished(taskContextCaptor.capture());
- assertThat(taskContextCaptor.getValue().getProjectAnalysis().getDate())
+ assertThat(taskContextCaptor.getValue().getProjectAnalysis().getAnalysis().get().getDate())
.isEqualTo(new Date(analysisMetadataHolder.getAnalysisDate()));
}
- @Test
- public void date_comes_from_system2_if_not_set_in_AnalysisMetadataHolder() {
- long now = 1_999_663L;
- when(system2.now()).thenReturn(now);
-
- underTest.finished(false);
-
- verify(postProjectAnalysisTask).finished(taskContextCaptor.capture());
-
- assertThat(taskContextCaptor.getValue().getProjectAnalysis().getDate()).isEqualTo(new Date(now));
- }
-
@Test
public void analysisDate_and_analysisUuid_comes_from_AnalysisMetadataHolder_when_set() {
analysisMetadataHolder.setAnalysisDate(8465132498L);
.finished(any(PostProjectAnalysisTask.Context.class));
new PostProjectAnalysisTasksExecutor(
- ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader,
- system2, new PostProjectAnalysisTask[] {logStatisticsTask})
+ ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader, new PostProjectAnalysisTask[] {logStatisticsTask})
.finished(allStepsExecuted);
verify(logStatisticsTask).finished(taskContextCaptor.capture());
new PostProjectAnalysisTasksExecutor(
ceTask, analysisMetadataHolder, qualityGateHolder, qualityGateStatusHolder, reportReader,
- system2, new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2, postProjectAnalysisTask3})
+ new PostProjectAnalysisTask[] {postProjectAnalysisTask1, postProjectAnalysisTask2, postProjectAnalysisTask3})
.finished(allStepsExecuted);
inOrder.verify(postProjectAnalysisTask1).finished(taskContextCaptor.capture());
- **Import your Azure DevOps repositories** - Import your Azure DevOps repositories into SonarQube to easily set up SonarQube projects.
- **Analyze projects with Azure Pipelines** - Integrate analysis into your build pipeline. Starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), SonarScanners running in Azure Pipelines jobs can automatically detect branches or pull requests being built, so you don't need to specifically pass them as parameters to the scanner.
-- **Add pull request decoration** - (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in Azure DevOps so you know if it's safe to merge your changes.
+- **Report your Quality Gate status to your pull requests** - (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in Azure DevOps so you know if it's safe to merge your changes.
## Prerequisites
Integration with Azure DevOps Server requires Azure DevOps Server 2020, Azure DevOps Server 2019, TFS 2018, or TFS 2017 Update 2.
| Invoke-WebRequest -Uri '<sonarqube_url>/static/cpp/build-wrapper-win-x86.zip' -OutFile 'build-wrapper.zip'
| Expand-Archive -Path 'build-wrapper.zip' -DestinationPath '.'
| ```
-| Example of bash commands on a linux host:
+| Example of bash commands on a Linux host:
| ```
| curl '<sonarqube_url>/static/cpp/build-wrapper-linux-x86.zip' --output build-wrapper.zip
| unzip build-wrapper.zip
| ```
| build-wrapper-win-x86/build-wrapper-win-x86-64.exe --out-dir <output directory> MSBuild.exe /t:Rebuild
| ```
-| Example of bash commands on a linux host with a *make* build:
+| Example of bash commands on a Linux host with a *make* build:
| ```
| build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir <output directory> make clean all
| ```
Check out this [![YouTube link](/images/youtube.png) video](https://www.youtube.com/watch?v=be5aw9_7bBU) for a quick overview on preventing pull requests from being merged when they are failing the Quality Gate.
-## Adding pull request decoration to Azure DevOps
-Pull request decoration shows your Quality Gate and analysis metrics directly in Azure DevOps.
+## Reporting your Quality Gate status in Azure DevOps
+After you've set up SonarQube to import your Azure DevOps repositories as shown in the **Importing your Azure DevOps repositories into SonarQube** above, SonarQube can report your Quality Gate status and analysis metrics directly to your Azure DevOps pull requests.
-After you've set up SonarQube to import your Azure DevOps repositories as shown in the **Importing your Azure DevOps repositories into SonarQube** above, the simplest way to add pull request decoration is by adding a project from Azure DevOps by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and selecting **Azure DevOps**.
+To do this, add a project from Azure DevOps by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and select **Azure DevOps** from the drop-down menu.
-Then, follow the steps in SonarQube to analyze your project. The project settings for pull request decoration are set automatically.
+Then, follow the steps in SonarQube to analyze your project. SonarQube automatically sets the project settings required to show your Quality Gate in your pull requests.
[[info]]
-| To decorate Pull Requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for Pull Request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
+| To report your Quality Gate status in your pull requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for pull request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
-### Adding pull request decoration to a manually created or existing project
-To add pull request decoration to a manually created or existing project, make sure your global ALM Integration settings are set as shown above in the **Importing your Azure DevOps repositories into SonarQube** section, and set the following project settings at **Project Settings > General Settings > Pull Request Decoration**:
+If you're creating your projects manually or adding Quality Gate reporting to an existing project, see the following section.
+
+### Reporting your Quality Gate status in manually created or existing projects
+SonarQube can also report your Quality Gate status to Azure DevOps pull requests for existing and manually-created projects. After setting your global settings as shown in the **Importing your Azure DevOps repositories into SonarQube** section above, set the following project settings at **Project Settings > General Settings > DevOps Platform Integration**:
- **Project name**
- **Repository name**
-### Advanced pull request decoration configuration
+### Advanced configuration
[[collapse]]
-| ## Adding pull request decoration to projects that are part of a mono repository
+| ## Reporting your Quality Gate status on pull requests in a mono repository
|
-| _Pull request decoration for a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
+| _Reporting Quality Gate statuses to pull requests in a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
|
-| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same Azure DevOps repository. You'll need to set up pull request decoration for each SonarQube project that is part of a mono repository.
+| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same Azure DevOps repository. You'll need to set up each SonarQube project that's part of a mono repository to report your Quality Gate status.
|
-| To add pull request decoration to a project that's part of a mono repository, set your project up manually as shown in the **Adding pull request decoration to a manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > Pull Request Decoration**.
+| You need to set up projects that are part of a mono repository manually as shown in the **Displaying your Quality Gate status in manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > DevOps Platform Integration**.
|
-| After setting your project settings, you need to ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
+| After setting your project settings, ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
|
| ### Ensuring the correct project is analyzed
| You need to adjust the analysis scope to make sure SonarQube doesn't analyze code from other projects in your mono repository. To do this set up a **Source File Inclusion** for your project at **Project Settings > Analysis Scope** with a pattern that will only include files from the appropriate folder. For example, adding `./MyFolderName/**/*` to your inclusions would only include analysis of code in the `MyFolderName` folder. See [Narrowing the Focus](/project-administration/narrowing-the-focus/) for more information on setting your analysis scope.
[[collapse]]
| ## Configuring multiple ALM instances
-|You can decorate pull requests from multiple ALM instances by creating a configuration for each ALM instance and then assigning that instance configuration to the appropriate projects.
+| SonarQube can report your Quality Gate status to multiple ALM instances. To do this, you need to create a configuration for each ALM instance and assign that configuration to the appropriate projects.
|
-|- As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
+| - As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
|
-|- Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
+| - Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
[[collapse]]
| ## Linking issues
-| During pull request decoration, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
+| When adding a Quality Gate status to your pull requests, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
## FAQ
- **Import your BitBucket Cloud repositories** – Import your Bitbucket Cloud repositories into SonarQube to easily set up SonarQube projects.
- **Analyze projects with Bitbucket Pipelines** – Integrate analysis into your build pipeline. SonarScanners running in Bitbucket Pipelines can automatically detect branches or pull requests being built so you don't need to specifically pass them as parameters to the scanner (branch and pull request analysis is available starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)).
+<<<<<<< HEAD
- **Add pull request decoration** – (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in Bitbucket Cloud so you know if it's safe to merge your changes.
+=======
+- **Report your Quality Gate status to your pull requests** – (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in Bitbucket Cloud so you know if it's safe to merge your changes.
+>>>>>>> SONAR-14851 Report Quality Gate status on branches in GitHub
## Importing your Bitbucket Cloud repositories into SonarQube
1. Add your Bitbucket username and an app password.
### Creating your OAuth consumer
+<<<<<<< HEAD
SonarQube uses a dedicated [OAuth consumer](https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/) to import repositories and decorate pull requests. Create the OAuth consumer in your Bitbucket Cloud workspace settings and specify the following:
+=======
+SonarQube uses a dedicated [OAuth consumer](https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/) to import repositories and display your Quality Gate status on pull requests. Create the OAuth consumer in your Bitbucket Cloud workspace settings and specify the following:
+>>>>>>> SONAR-14851 Report Quality Gate status on branches in GitHub
- **Name** – the name of your OAuth consumer
- **Callback URL** – Bitbucket Cloud requires this field, but it's not used by SonarQube so you can use any URL.
Then, you'll be asked to provide your Bitbucket username and an [app password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/). Your app password needs the **repository:read** permission.
+<<<<<<< HEAD
After adding your Bitbucket username and app password, you'll see a list of your Bitbucket Cloud projects that you can **set up** to add them to SonarQube. Setting up your projects this way also sets your project settings for pull request decoration.
+=======
+After adding your Bitbucket username and app password, you'll see a list of your Bitbucket Cloud projects that you can **set up** to add them to SonarQube. Setting up your projects this way also sets your project settings for displaying your Quality Gate status on pull requests.
+>>>>>>> SONAR-14851 Report Quality Gate status on branches in GitHub
## Analyzing projects with Bitbucket Pipelines
SonarScanners running in Bitbucket Pipelines can automatically detect branches or pull requests being built so you don't need to specifically pass them as parameters to the scanner.
If you do not want to use the SonarQube Quality Gate Check Pipe, you can instruct the scanner to wait for the SonarQube Quality Gate status at the end of the analysis. To enable this, pass the `-Dsonar.qualitygate.wait=true` parameter to the scanner in the `bitbucket-pipelines.yml` file.
-This will make the analysis step poll SonarQube regularly until the Quality Gate is computed. This will increase your pipeline duration. Note that, if the Quality Gate is red, this will make the analysis step fail, even if the actual analysis itself is successful. We advise only using this parameter when necessary (for example, to block a deployment pipeline if the Quality Gate is red). It should not be used to report the Quality Gate status in a pull request, as this is already done with pull request decoration.
+This will make the analysis step poll SonarQube regularly until the Quality Gate is computed. This will increase your pipeline duration. Note that, if the Quality Gate is red, this will make the analysis step fail, even if the actual analysis itself is successful. We advise only using this parameter when necessary (for example, to block a deployment pipeline if the Quality Gate is red). It should not be used to report the Quality Gate status in a pull request.
You can set the `sonar.qualitygate.timeout` property to an amount of time (in seconds) that the scanner should wait for a report to be processed. The default is 300 seconds.
### For more information
For more information on configuring your build with Bitbucket Pipelines, see the [Configure bitbucket-pipelines.yml](https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/) documentation provided by Atlassian.
+<<<<<<< HEAD
## Adding Pull Request decoration to Bitbucket Cloud
After creating and installing your OAuth consumer above, you can add pull request decoration to show your Quality Gate and analysis metrics directly in Bitbucket Cloud.
### Adding pull request decoration to a manually created or existing project.
To add pull request decoration to a manually created or existing project, after you've created and installed your OAuth consumer and updated your global settings as shown in the **Importing your Bitbucket Cloud repositories into SonarQube** section above, set the following project settings at **Project Settings > General Settings > Pull Request Decoration**:
+=======
+## Reporting your Quality Gate status in Bitbucket Cloud
+
+After creating and installing your OAuth consumer above, SonarQube can report your Quality Gate status and analysis metrics directly to your Bitbucket Cloud pull requests.
+
+To do this, add a project from Bitbucket by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and select **Bitbucket** from the drop-down menu.
+
+Then, follow the steps in SonarQube to analyze your project. SonarQube automatically sets the project settings required to show your Quality Gate in your pull requests.
+
+[[info]]
+| To report your Quality Gate status in your pull requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for pull request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
+
+If you're creating your projects manually or adding Quality Gate reporting to an existing project, see the following section.
+
+### Reporting your Quality Gate status in manually created or existing projects
+SonarQube can also report your Quality Gate status to Bitbucket Cloud pull requests for existing and manually-created projects. After you've created and installed your OAuth consumer and updated your global settings as shown in the **Importing your Bitbucket Cloud repositories into SonarQube** section above, set the following project settings at **Project Settings > General Settings > DevOps Platform Integration**:
+>>>>>>> SONAR-14851 Report Quality Gate status on branches in GitHub
- **Configuration name** – The configuration name that corresponds to your GitHub instance.
- **Repository SLUG** – The Repository SLUG is part of your Bitbucket Cloud URL. For example, `https://bitbucket.org/{workspace}/{repository}`
-### Advanced pull request decoration configuration
+### Advanced configuration
[[collapse]]
-| ## Adding pull request decoration to projects that are part of a mono repository
+| ## Reporting your Quality Gate status on pull requests in a mono repository
|
-| _Pull request decoration for a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
+| _Reporting Quality Gate statuses to pull requests in a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
|
-| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same Bitbucket Cloud repository. You'll need to set up pull request decoration for each SonarQube project that is part of a mono repository.
+| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same Bitbucket Cloud repository. You'll need to set up each SonarQube project that's part of a mono repository to report your Quality Gate status.
|
-| To add pull request decoration to a project that's part of a mono repository, set your project up as shown in the **Adding pull request decoration to Bitbucket Cloud** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > Pull Request Decoration** .
+| You need to set up projects that are part of a mono repository manually as shown in the **Displaying your Quality Gate status in manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > DevOps Platform Integration**.
|
-| After setting your project settings, you need to ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
+| After setting your project settings, ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
|
| ### Ensuring the correct project is analyzed
| You need to adjust the analysis scope to make sure SonarQube doesn't analyze code from other projects in your mono repository. To do this set up a **Source File Inclusion** for your project at **Project Settings > Analysis Scope** with a pattern that will only include files from the appropriate folder. For example, adding `./MyFolderName/**/*` to your inclusions would only include analysis of code in the `MyFolderName` folder. See [Narrowing the Focus](/project-administration/narrowing-the-focus/) for more information on setting your analysis scope.
[[collapse]]
| ## Configuring multiple ALM instances
-|You can decorate pull requests from multiple ALM instances by creating a configuration for each ALM instance and then assigning that instance configuration to the appropriate projects.
+| SonarQube can report your Quality Gate status to multiple ALM instances. To do this, you need to create a configuration for each ALM instance and assign that configuration to the appropriate projects.
|
-|- As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
+| - As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
|
-|- Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
+| - Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
[[collapse]]
| ## Linking issues
-| During pull request decoration, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
+| When adding a Quality Gate status to your pull requests, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
With this integration, you'll be able to:
- **Import your BitBucket Server repositories** - Import your Bitbucket Server repositories into SonarQube to easily set up SonarQube projects.
-- **Add pull request decoration** - (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in Bitbucket Server so you know if it's safe to merge your changes.
+- **Report your Quality Gate status to your pull requests** - (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in Bitbucket Server so you know if it's safe to merge your changes.
## Prerequisites
Integration with Bitbucket Server requires at least Bitbucket Server version 5.15.
After saving your personal access token, you'll see a list of your Bitbucket Server projects that you can **set up** to add them to SonarQube. Setting up your projects this way also sets your project settings for pull request decoration.
-## Adding pull request decoration to Bitbucket Server
-Pull request decoration shows your Quality Gate and analysis metrics directly in Bitbucket Server:
+## Reporting your Quality Gate status to Bitbucket Server
+After you've set up SonarQube to import your Bitbucket Server repositories as shown in the previous section, SonarQube can report your Quality Gate status and analysis metrics directly to your Bitbucket Server pull requests.
-After you've set up SonarQube to import your Bitbucket Server repositories as shown in the previous section, the simplest way to add pull request decoration is by adding a project from Bitbucket Server by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and selecting **Bitbucket**.
+To do this, add a project from Bitbucket by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and select **Bitbucket** from the drop-down menu.
-Then, follow the steps in SonarQube to analyze your project. The project settings for pull request decoration are set automatically.
+Then, follow the steps in SonarQube to analyze your project. SonarQube automatically sets the project settings required to show your Quality Gate in your pull requests.
[[info]]
-| To decorate Pull Requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for Pull Request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
+| To report your Quality Gate status in your pull requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for pull request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
-### Adding pull request decoration to a manually created or existing project
-To add pull request decoration to a manually created or existing project, make sure your global ALM Integration settings are configured as shown in the **Importing your Bitbucket Server repositories into SonarQube** section above, and set the following project settings at **Project Settings > General Settings > Pull Request Decoration**:
+If you're creating your projects manually or adding Quality Gate reporting to an existing project, see the following section.
+
+### Reporting your Quality Gate status in manually created or existing projects
+SonarQube can also report your Quality Gate status to Bitbucket Server for existing projects and manually-created projects. After you've updated your global settings as shown in the **Importing your Bitbucket Server repositories into SonarQube** section above, set the following project settings at **Project Settings > General Settings > DevOps Platform Integration**:
- **Configuration name** – The configuration name that corresponds to your ALM instance.
- **Project Key** – the project key is part of your BitBucket Server repository URL (.../projects/**{KEY}**/repos/{SLUG}/browse).
- **Repository SLUG** – The repository slug is part of your BitBucket Server repository URL (.../projects/{KEY}/repos/**{SLUG}**/browse).
-### Advanced pull request decoration configuration
+### Advanced configuration
[[collapse]]
-| ## Adding pull request decoration to projects that are part of a mono repository
+| ## Reporting your Quality Gate status on pull requests in a mono repository
|
-| _Pull request decoration for a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
+| _Reporting Quality Gate statuses to pull requests in a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
|
-| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same Bitbucket Server repository. You'll need to set up pull request decoration for each SonarQube project that is part of a mono repository.
+| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same Bitbucket Server repository. You'll need to set up each SonarQube project that's part of a mono repository to report your Quality Gate status.
|
-| To add pull request decoration to a project that's part of a mono repository, set your project up manually as shown in the **Adding pull request decoration to a manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > Pull Request Decoration**.
+| You need to set up projects that are part of a mono repository manually as shown in the **Reporting your Quality Gate status in manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > DevOps Platform Integration**.
|
-| After setting your project settings, you need to ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
+| After setting your project settings, ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
|
| ### Ensuring the correct project is analyzed
| You need to adjust the analysis scope to make sure SonarQube doesn't analyze code from other projects in your mono repository. To do this set up a **Source File Inclusion** for your project at **Project Settings > Analysis Scope** with a pattern that will only include files from the appropriate folder. For example, adding `./MyFolderName/**/*` to your inclusions would only include analysis of code in the `MyFolderName` folder. See [Narrowing the Focus](/project-administration/narrowing-the-focus/) for more information on setting your analysis scope.
[[collapse]]
| ## Configuring multiple ALM instances
-|You can decorate pull requests from multiple ALM instances by creating a configuration for each ALM instance and then assigning that instance configuration to the appropriate projects.
+| SonarQube can report your Quality Gate status to multiple ALM instances. To do this, you need to create a configuration for each ALM instance and assign that configuration to the appropriate projects.
|
-|- As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
+| - As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
|
-|- Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
+| - Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
[[collapse]]
| ## Linking issues
-| During pull request decoration, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
+| When adding a Quality Gate status to your pull requests, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
## Preventing pull request merges when the Quality Gate fails
After setting up pull request analysis, you can block pull requests from being merged if it is failing the Quality Gate. To do this:
- **Import your GitHub repositories** - Import your GitHub repositories into SonarQube to easily set up SonarQube projects.
- **Analyze projects with GitHub Actions** - Integrate analysis into your build pipeline. Starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), SonarScanners running in GitHub Actions jobs can automatically detect branches or pull requests being built so you don't need to specifically pass them as parameters to the scanner.
-- **Add pull request decoration** - (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in GitHub so you know if it's safe to merge your changes.
+- **Report your Quality Gate status to your branches and pull requests** - (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in GitHub so you know if it's safe to merge your changes.
- **Authenticate with GitHub** - Sign in to SonarQube with your GitHub credentials.
## Prerequisites
If you do not want to use the SonarQube Quality Gate Check Action, you can instruct the scanner to wait for the SonarQube Quality Gate status at the end of the analysis. To enable this, pass the `-Dsonar.qualitygate.wait=true` parameter to the scanner in the workflow YAML file.
+<<<<<<< HEAD
This will make the analysis step poll SonarQube regularly until the Quality Gate is computed. This will increase your pipeline duration. Note that, if the Quality Gate is red, this will make the analysis step fail, even if the actual analysis itself is successful. We advise only using this parameter when necessary (for example, to block a deployment pipeline if the Quality Gate is red). It should not be used to report the Quality Gate status in a pull request, as this is already done with pull request decoration.
+=======
+This will make the analysis step poll SonarQube regularly until the Quality Gate is computed. This will increase your pipeline duration. Note that, if the Quality Gate is red, this will make the analysis step fail, even if the actual analysis itself is successful. We advise only using this parameter when necessary (for example, to block a deployment pipeline if the Quality Gate is red). It should not be used to report the Quality Gate status in a pull request.
+>>>>>>> SONAR-14851 Report Quality Gate status on branches in GitHub
You can set the `sonar.qualitygate.timeout` property to an amount of time (in seconds) that the scanner should wait for a report to be processed. The default is 300 seconds.
### Commit and push your code
Commit and push your code to start the analysis. Each new push you make on your branches or pull requests will trigger a new analysis in SonarQube.
-## Adding pull request decoration to GitHub
-After creating and installing your GitHub App above, you can add pull request decoration to show your Quality Gate and analysis metrics directly in GitHub:
+## Reporting your Quality Gate status in GitHub
+After creating and installing your GitHub App above, SonarQube can report your Quality Gate status and analysis metrics directly to your GitHub branches and pull requests.
-The simplest way to add pull request decoration is by adding a project from GitHub by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and selecting **GitHub**.
+To do this, add a project from GitHub by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and select **GitHub** from the drop-down menu.
-Then, follow the steps in SonarQube to analyze your project. The project settings for pull request decoration are set automatically.
+Then, follow the steps in SonarQube to analyze your project. SonarQube automatically sets the project settings required to show your Quality Gate in your branches and pull requests.
[[info]]
-| To decorate Pull Requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for Pull Request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
+| To report your Quality Gate status in your branches and pull requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for pull request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
-### Adding pull request decoration to a manually created or existing project
-To add pull request decoration to a manually created or existing project, after you've created and installed your GitHub App and updated your global ALM Integration settings as shown in the **Importing your GitHub repositories into SonarQube** section above, set the following project settings at **Project Settings > General Settings > Pull Request Decoration**:
+If you're creating your projects manually or adding Quality Gate reporting to an existing project, see the following section.
+
+### Reporting your Quality Gate status in manually created or existing projects
+SonarQube can also report your Quality Gate status to GitHub pull requests and branches for existing and manually-created projects. After you've created and installed your GitHub App and updated your global ALM Integration settings as shown in the **Importing your GitHub repositories into SonarQube** section above, set the following project settings at **Project Settings > General Settings > DevOps Platform Integration**:
- **Configuration name** – The configuration name that corresponds to your GitHub instance.
- **Repository identifier** – The path of your repository URL.
-### Advanced pull request decoration configuration
+### Advanced configuration
[[collapse]]
-| ## Adding pull request decoration to projects that are part of a mono repository
+| ## Reporting your Quality Gate status on pull requests and branches in a mono repository
|
-| _Pull request decoration for a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
+| _Reporting Quality Gate statuses to branches and pull requests in a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
|
-| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same GitHub repository. You'll need to set up pull request decoration for each SonarQube project that is part of a mono repository.
+| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same GitHub repository. You'll need to set up each SonarQube project that's part of a mono repository to report your Quality Gate status.
|
-| To add pull request decoration to a project that's part of a mono repository, set your project up manually as shown in the **Adding pull request decoration to a manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > Pull Request Decoration**.
+| You need to set up projects that are part of a mono repository manually as shown in the **Displaying your Quality Gate status in manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > DevOps Platform Integration**.
|
-| After setting your project settings, you need to ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
+| After setting your project settings, ensure that the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
|
| ### Ensuring the correct project is analyzed
| You need to adjust the analysis scope to make sure SonarQube doesn't analyze code from other projects in your mono repository. To do this set up a **Source File Inclusion** for your project at **Project Settings > Analysis Scope** with a pattern that will only include files from the appropriate folder. For example, adding `./MyFolderName/**/*` to your inclusions would only include analysis of code in the `MyFolderName` folder. See [Narrowing the Focus](/project-administration/narrowing-the-focus/) for more information on setting your analysis scope.
| Because of the nature of a mono repository, SonarQube scanners might read all project names of your mono repository as identical. To avoid having multiple projects with the same name, you need to pass the `sonar.projectName` parameter to the scanner. For example, if you're using the Maven scanner, you would pass `mvn sonar:sonar -Dsonar.projectName=YourProjectName`.
[[collapse]]
-| ## Showing the analysis summary under the GitHub Conversation tab
+| ## Showing your analysis summary under the GitHub Conversation tab
| By default, **Enable analysis summary under the GitHub Conversation tab** is on and your pull request analysis will be shown under both the **Conversation** and **Checks** tabs in GitHub. When off, your pull request analysis summary is only shown under the **Checks** tab.
[[collapse]]
| ## Configuring multiple ALM instances
-|You can decorate pull requests from multiple ALM instances by creating a configuration for each ALM instance and then assigning that instance configuration to the appropriate projects.
+| SonarQube can report your Quality Gate status to multiple ALM instances. To do this, you need to create a configuration for each ALM instance and assign that configuration to the appropriate projects.
|
-|- As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
+| - As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
|
-|- Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
+| - Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
[[collapse]]
| ## Linking issues
-| During pull request decoration, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
+| When adding a Quality Gate status to your pull requests and branches, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
## Setting up GitHub authentication
To allow users to log in with GitHub credentials, use the GitHub App that you created above (see the **Importing your GitHub repositories using a GitHub App** section for more information) and update your global SonarQube settings.
- **Authenticate with GitLab** - Sign in to SonarQube with your GitLab credentials.
- **Import your GitLab projects** - Import your GitLab Projects into SonarQube to easily set up SonarQube projects.
- **Analyze projects with GitLab CI/CD** - Integrate analysis into your build pipeline. Starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), SonarScanners running in GitLab CI/CD jobs can automatically detect branches or merge requests being built so you don't need to specifically pass them as parameters to the scanner.
-- **Add merge request decoration** - (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in GitLab so you know if it's safe to merge your changes.
+- **Report your Quality Gate status to your merge requests** - (starting in [Developer Edition](https://redirect.sonarsource.com/editions/developer.html)) See your Quality Gate and code metric results right in GitLab so you know if it's safe to merge your changes.
## Prerequisites
Integration with GitLab Self-Managed requires at least GitLab Self-Managed version 11.7.
### For more information
For more information on configuring your build with GitLab CI/CD, see the [GitLab CI/CD Pipeline Configuration Reference](https://gitlab.com/help/ci/yaml/README.md).
-## Adding merge request decoration to GitLab
+## Reporting your Quality Gate status in GitLab
-Merge request decoration shows your Quality Gate and analysis metrics directly in GitLab.
+After you've set up SonarQube to import your GitLab projects as shown in the previous section, SonarQube can report your Quality Gate status and analysis metrics directly to GitLab.
-After you've set up SonarQube to import your GitLab projects as shown in the previous section, the simplest way to add merge request decoration is by adding a project from GitLab by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and selecting **GitLab**.
+To do this, add a project from GitLab by clicking the **Add project** button in the upper-right corner of the **Projects** homepage and select **GitLab** from the drop-down menu.
-Then, follow the steps in SonarQube to analyze your project. The project settings for merge request decoration are set automatically.
+Then, follow the steps in SonarQube to analyze your project. SonarQube automatically sets the project settings required to show your Quality Gate in your merge requests.
[[info]]
-| To decorate merge requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for merge request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
+| To report your Quality Gate status in your merge requests, a SonarQube analysis needs to be run on your code. You can find the additional parameters required for merge request analysis on the [Pull Request Analysis](/analysis/pull-request/) page.
-### Adding merge request decoration to a manually created or existing project
-To add merge request decoration to a manually created or existing project, make sure your global ALM Integration settings are set as shown in the **Importing your GitLab projects into SonarQube** section above, and set the following project settings at **Project Settings > General Settings > Pull Request Decoration**:
+If you're creating your projects manually or adding Quality Gate reporting to an existing project, see the following section.
+
+### Reporting your Quality Gate status in manually created or existing projects
+SonarQube can also report your Quality Gate status to GitLab merge requests for existing and manually-created projects. After you've updated your global settings as shown in the **Importing your GitLab projects into SonarQube** section above, set the following project settings at **Project Settings > General Settings > DevOps Platform Integration**:
- **Configuration name** – The configuration name that corresponds to your GitLab instance.
- **Project ID** – your GitLab Project ID found in GitLab
-### Advanced merge request decoration configuration
+### Advanced configuration
[[collapse]]
-| ## Adding merge request decoration to projects that are part of a mono repository
+| ## Reporting your Quality Gate status on pull requests in a mono repository
|
-| _Pull request decoration for a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
+| _Reporting Quality Gate statuses to merge requests in a mono repository setup is supported starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html)._
|
-| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same GitLab repository. You'll need to set up merge request decoration for each SonarQube project that is part of a mono repository.
+| In a mono repository setup, multiple SonarQube projects, each corresponding to a separate project within the mono repository, are all bound to the same Bitbucket Cloud repository. You'll need to set up each SonarQube project that's part of a mono repository to report your Quality Gate status.
|
-| To add merge request decoration to a project that's part of a mono repository, set your project up manually as shown in the **Adding merge request decoration to a manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > Pull Request Decoration**.
+| You need to set up projects that are part of a mono repository manually as shown in the **Displaying your Quality Gate status in manually created or existing project** section above. You also need to set the **Enable mono repository support** setting to true at **Project Settings > General Settings > DevOps Platform Integration**.
|
-| After setting your project settings, you need to ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
+| After setting your project settings, ensure the correct project is being analyzed by adjusting the analysis scope and pass your project names to the scanner. See the following sections for more information.
|
| ### Ensuring the correct project is analyzed
| You need to adjust the analysis scope to make sure SonarQube doesn't analyze code from other projects in your mono repository. To do this set up a **Source File Inclusion** for your project at **Project Settings > Analysis Scope** with a pattern that will only include files from the appropriate folder. For example, adding `./MyFolderName/**/*` to your inclusions would only include analysis of code in the `MyFolderName` folder. See [Narrowing the Focus](/project-administration/narrowing-the-focus/) for more information on setting your analysis scope.
[[collapse]]
| ## Configuring multiple ALM instances
-|You can decorate merge requests from multiple ALM instances by creating a configuration for each ALM instance and then assigning that instance configuration to the appropriate projects.
+| SonarQube can report your Quality Gate status to multiple ALM instances. To do this, you need to create a configuration for each ALM instance and assign that configuration to the appropriate projects.
|
-|- As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
+| - As part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html), you can create one configuration for each ALM.
|
-|- Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
+| - Starting in [Enterprise Edition](https://redirect.sonarsource.com/editions/enterprise.html), you can create multiple configurations for each ALM. If you have multiple configurations of the same ALM connected to SonarQube, you have to create projects manually.
[[collapse]]
| ## Linking issues
-| During merge request decoration, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
+| When adding a Quality Gate status to your merge requests, individual issues will be linked to their SonarQube counterparts automatically. For this to work correctly, you need to set the instance's **Server base URL** (**[Administration > Configuration > General Settings > General > General](/#sonarqube-admin#/admin/settings/)**) correctly. Otherwise, the links will default to `localhost`.
MAJOR, C,
MINOR, B,
INFO, A);
+
+
+ public static Rating ratingFromValue(String value) {
+ return valueOf(Integer.parseInt(value));
+ }
}
return STATUS_ICON[type];
}
+function getPrDecoFeatureDescription(alm: AlmKeys) {
+ switch (alm) {
+ case AlmKeys.GitLab:
+ return translate('settings.almintegration.feature.status_reporting.description_mr');
+ case AlmKeys.GitHub:
+ return translate(
+ 'settings.almintegration.feature.status_reporting.description_pr_and_commits'
+ );
+ default:
+ return translate('settings.almintegration.feature.status_reporting.description_pr');
+ }
+}
+
export default function AlmBindingDefinitionBox(props: AlmBindingDefinitionBoxProps) {
const { alm, branchesEnabled, definition, multipleDefinitions, status = DEFAULT_STATUS } = props;
- const prDecoFeatureTitle =
- alm === AlmKeys.GitLab
- ? translate('settings.almintegration.feature.mr_decoration.title')
- : translate('settings.almintegration.feature.pr_decoration.title');
-
- const prDecoFeatureDescription =
- alm === AlmKeys.GitLab
- ? translate('settings.almintegration.feature.mr_decoration.description')
- : translate('settings.almintegration.feature.pr_decoration.description');
-
return (
<div className="boxed-group-inner bordered spacer-top spacer-bottom it__alm-binding-definition">
<div className="actions pull-right">
{status.type !== AlmSettingsBindingStatusType.Warning && (
<div className="display-flex-row spacer-bottom">
<div className="huge-spacer-right">
- <Tooltip overlay={prDecoFeatureDescription}>
- <span>{prDecoFeatureTitle}</span>
+ <Tooltip overlay={getPrDecoFeatureDescription(alm)}>
+ <span>{translate('settings.almintegration.feature.status_reporting.title')}</span>
</Tooltip>
{getPRDecorationFeatureStatus(branchesEnabled, status.type)}
</div>
className="huge-spacer-right"
>
<Tooltip
- overlay="settings.almintegration.feature.pr_decoration.description"
+ overlay="settings.almintegration.feature.status_reporting.description_pr_and_commits"
>
<span>
- settings.almintegration.feature.pr_decoration.title
+ settings.almintegration.feature.status_reporting.title
</span>
</Tooltip>
<AlertErrorIcon
className="huge-spacer-right"
>
<Tooltip
- overlay="settings.almintegration.feature.pr_decoration.description"
+ overlay="settings.almintegration.feature.status_reporting.description_pr_and_commits"
>
<span>
- settings.almintegration.feature.pr_decoration.title
+ settings.almintegration.feature.status_reporting.title
</span>
</Tooltip>
<AlertSuccessIcon
className="huge-spacer-right"
>
<Tooltip
- overlay="settings.almintegration.feature.pr_decoration.description"
+ overlay="settings.almintegration.feature.status_reporting.description_pr"
>
<span>
- settings.almintegration.feature.pr_decoration.title
+ settings.almintegration.feature.status_reporting.title
</span>
</Tooltip>
<AlertSuccessIcon
className="huge-spacer-right"
>
<Tooltip
- overlay="settings.almintegration.feature.mr_decoration.description"
+ overlay="settings.almintegration.feature.status_reporting.description_mr"
>
<span>
- settings.almintegration.feature.mr_decoration.title
+ settings.almintegration.feature.status_reporting.title
</span>
</Tooltip>
<AlertSuccessIcon
className="huge-spacer-right"
>
<Tooltip
- overlay="settings.almintegration.feature.pr_decoration.description"
+ overlay="settings.almintegration.feature.status_reporting.description_pr_and_commits"
>
<span>
- settings.almintegration.feature.pr_decoration.title
+ settings.almintegration.feature.status_reporting.title
</span>
</Tooltip>
<AlertSuccessIcon
className="huge-spacer-right"
>
<Tooltip
- overlay="settings.almintegration.feature.pr_decoration.description"
+ overlay="settings.almintegration.feature.status_reporting.description_pr_and_commits"
>
<span>
- settings.almintegration.feature.pr_decoration.title
+ settings.almintegration.feature.status_reporting.title
</span>
</Tooltip>
<div
multipleAlmFeatureProvider)));
@Before
- public void before(){
+ public void before() {
when(multipleAlmFeatureProvider.enabled()).thenReturn(false);
}
settings.almintegration.form.cancel=Cancel
settings.almintegration.form.secret_field=This field is hidden for security reasons.
settings.almintegration.form.update_secret_field=Update field value
-settings.almintegration.feature.pr_decoration.title=Pull Request Decoration
-settings.almintegration.feature.pr_decoration.description=Add analysis and a Quality Gate to your Pull Requests directly in your ALM provider's interface.
-settings.almintegration.feature.mr_decoration.title=Merge Request Decoration
-settings.almintegration.feature.mr_decoration.description=Add analysis and a Quality Gate to your Merge Requests directly in your ALM provider's interface.
+settings.almintegration.feature.status_reporting.title=Quality Gate status reporting
+settings.almintegration.feature.status_reporting.description_pr=Add analysis and a Quality Gate to your Pull Requests directly in your ALM provider's interface.
+settings.almintegration.feature.status_reporting.description_pr_and_commits=Add the Quality Gate status to your Pull Requests and on analyzed commits directly in your ALM provider's interface.
+settings.almintegration.feature.status_reporting.description_mr=Add analysis and a Quality Gate to your Merge Requests directly in your ALM provider's interface.
settings.almintegration.feature.pr_decoration.disabled=Disabled
settings.almintegration.feature.pr_decoration.disabled.no_branches=Upgrade to {link} to enable this feature.
settings.almintegration.feature.pr_decoration.disabled.no_branches.link=Developer Edition
settings.almintegration.feature.alm_repo_import.disabled.multiple=This feature is disabled because you have 2 or more integration instances configured.
settings.almintegration.feature.alm_repo_import.disabled.no_url=This feature is disabled because your configured instance has no URL.
-settings.pr_decoration.binding.category=Pull Request Decoration
+settings.pr_decoration.binding.category=DevOps Platform Integration
settings.pr_decoration.binding.no_bindings=This feature must first be enabled in the global settings. {link}
-settings.pr_decoration.binding.title=Pull Request Decoration
-settings.pr_decoration.binding.description=Enable Pull Request Decoration for this project.
+settings.pr_decoration.binding.title=DevOps Platform Integration
+settings.pr_decoration.binding.description=Display your Quality Gate status directly in your DevOps Platform.
settings.pr_decoration.binding.form.url=Project location
settings.pr_decoration.binding.form.name=Configuration name
settings.pr_decoration.binding.form.monorepo=Enable mono repository support
@CheckForNull
QualityGate getQualityGate();
- /**
- * Date of the analysis.
- * <p>
- * This date is the same as the date of the project analysis report and the snapshot.
- *
- * @deprecated use {@link #getAnalysis().getDate()} instead. When {@link #getAnalysis()} returns
- * {@link Optional#empty() empty}, the current date will be returned.
- */
- @Deprecated
- Date getDate();
-
- /**
- * Date of the analysis.
- * <p>
- * This date is the same as the date of the project analysis report and therefore as the analysis in DB. It can be
- * missing when the status of the task is {@link org.sonar.api.ce.posttask.CeTask.Status#FAILED FAILED}.
- * </p>
- * @deprecated use {@link #getAnalysis().getDate()} instead
- */
- @Deprecated
- Optional<Date> getAnalysisDate();
-
/**
* Analysis containing the UUID of the analysis and the date
*
private static final String NAME_CAN_NOT_BE_NULL = "name cannot be null";
private final PostProjectAnalysisTask underTest;
- @Nullable
- private Organization organization;
@CheckForNull
private CeTask ceTask;
@CheckForNull
/**
* @since 7.0
*/
- public static OrganizationBuilder newOrganizationBuilder() {
- return new OrganizationBuilder();
- }
-
public static CeTaskBuilder newCeTaskBuilder() {
return new CeTaskBuilder();
}
return new ScannerContextBuilder();
}
- /**
- * @since 7.0
- */
- public PostProjectAnalysisTaskTester withOrganization(@Nullable Organization organization) {
- this.organization = organization;
- return this;
- }
-
public PostProjectAnalysisTaskTester withCeTask(CeTask ceTask) {
this.ceTask = requireNonNull(ceTask, CE_TASK_CAN_NOT_BE_NULL);
return this;
}
PostProjectAnalysisTask.ProjectAnalysis projectAnalysis = new ProjectAnalysisBuilder()
- .setOrganization(organization)
.setCeTask(ceTask)
.setProject(project)
.setBranch(branch)
return stats;
}
- public static final class OrganizationBuilder {
- @CheckForNull
- private String name;
- @CheckForNull
- private String key;
-
- private OrganizationBuilder() {
- // prevents instantiation
- }
-
- public OrganizationBuilder setName(String name) {
- this.name = requireNonNull(name, NAME_CAN_NOT_BE_NULL);
- return this;
- }
-
- public OrganizationBuilder setKey(String key) {
- this.key = requireNonNull(key, KEY_CAN_NOT_BE_NULL);
- return this;
- }
-
- public Organization build() {
- requireNonNull(this.name, NAME_CAN_NOT_BE_NULL);
- requireNonNull(this.key, KEY_CAN_NOT_BE_NULL);
- return new Organization() {
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getKey() {
- return key;
- }
-
- @Override
- public String toString() {
- return "Organization{" +
- "name='" + name + '\'' +
- ", key='" + key + '\'' +
- '}';
- }
- };
- }
- }
-
public static final class CeTaskBuilder {
private static final String ID_CAN_NOT_BE_NULL = "id cannot be null";
}
public static final class ProjectAnalysisBuilder {
- private Organization organization;
private CeTask ceTask;
private Project project;
private Branch branch;
// prevents instantiation outside PostProjectAnalysisTaskTester
}
- public ProjectAnalysisBuilder setOrganization(@Nullable Organization organization) {
- this.organization = organization;
- return this;
- }
-
public ProjectAnalysisBuilder setCeTask(CeTask ceTask) {
this.ceTask = ceTask;
return this;
return new PostProjectAnalysisTask.ProjectAnalysis() {
@Override
public Optional<Organization> getOrganization() {
- return Optional.ofNullable(organization);
+ return Optional.empty();
}
@Override
return qualityGate;
}
- @Override
- public Date getDate() {
- return date;
- }
-
- @Override
- public Optional<Date> getAnalysisDate() {
- return getAnalysis().map(Analysis::getDate);
- }
-
@Override
public Optional<Analysis> getAnalysis() {
return Optional.ofNullable(analysis);
@Override
public String toString() {
return "ProjectAnalysis{" +
- "organization=" + organization +
- ", ceTask=" + ceTask +
+ "ceTask=" + ceTask +
", project=" + project +
", date=" + date.getTime() +
", analysisDate=" + date.getTime() +
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private Organization organization = mock(Organization.class);
private CeTask ceTask = mock(CeTask.class);
private Project project = mock(Project.class);
private long someDateAsLong = 846351351684351L;
@Test
public void verify_getters_of_ProjectAnalysis_object_passed_to_PostProjectAnalysisTask() {
- underTest.withOrganization(organization).withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).withAnalysisUuid(analysisUuid).at(someDate);
+ underTest.withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).withAnalysisUuid(analysisUuid).at(someDate);
underTest.execute();
PostProjectAnalysisTask.ProjectAnalysis projectAnalysis = captorPostProjectAnalysisTask.projectAnalysis;
assertThat(projectAnalysis).isNotNull();
- assertThat(projectAnalysis.getOrganization().get()).isSameAs(organization);
assertThat(projectAnalysis.getCeTask()).isSameAs(ceTask);
assertThat(projectAnalysis.getProject()).isSameAs(project);
- assertThat(projectAnalysis.getDate()).isSameAs(someDate);
assertThat(projectAnalysis.getQualityGate()).isSameAs(qualityGate);
assertThat(projectAnalysis.getAnalysis().get().getAnalysisUuid()).isSameAs(analysisUuid);
}
@Test
public void verify_toString_of_ProjectAnalysis_object_passed_to_PostProjectAnalysisTask() {
- when(organization.toString()).thenReturn("Organization");
when(ceTask.toString()).thenReturn("CeTask");
when(project.toString()).thenReturn("Project");
when(qualityGate.toString()).thenReturn("QualityGate");
- underTest.withOrganization(organization).withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).at(someDate);
+ underTest.withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).at(someDate);
underTest.execute();
- assertThat(captorPostProjectAnalysisTask.projectAnalysis.toString())
- .isEqualTo("ProjectAnalysis{organization=Organization, ceTask=CeTask, project=Project, date=846351351684351, analysisDate=846351351684351, qualityGate=QualityGate}");
+ assertThat(captorPostProjectAnalysisTask.projectAnalysis)
+ .hasToString("ProjectAnalysis{ceTask=CeTask, project=Project, date=846351351684351, analysisDate=846351351684351, qualityGate=QualityGate}");
}
@Test
public void getLogStatistics_returns_empty_if_no_log_statistic_added_by_tested_Task() {
- underTest.withOrganization(organization).withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).withAnalysisUuid(analysisUuid).at(someDate);
+ underTest.withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).withAnalysisUuid(analysisUuid).at(someDate);
underTest.execute();
return null;
}).when(projectAnalysisTask).finished(any(PostProjectAnalysisTask.Context.class));
PostProjectAnalysisTaskTester underTest = PostProjectAnalysisTaskTester.of(projectAnalysisTask);
- underTest.withOrganization(organization).withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).withAnalysisUuid(analysisUuid).at(someDate);
+ underTest.withCeTask(ceTask).withProject(project).withQualityGate(qualityGate).withAnalysisUuid(analysisUuid).at(someDate);
underTest.execute();