Skip to content

Commit 7509f9b

Browse files
authored
Merge pull request #4565 from Microsoft/users/jpricket/m119
Cherry pick fix from master
2 parents edb97d0 + 07fc5c6 commit 7509f9b

File tree

2 files changed

+10
-56
lines changed

2 files changed

+10
-56
lines changed

Tasks/Maven/CodeAnalysis/SonarQube/vsts-server-utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ export class VstsServerUtils {
2626
* @returns {boolean} True if the build is a PR build, false otherwise.
2727
*/
2828
public static isPrBuild(): boolean {
29+
////////////////////////////////////////////////////////////////////////////////////////////////////////////
30+
// Changing the behavior of the SonarCube integration if this is a PR build causes at least one known bug
31+
// Because of this bug and other concerns we are disabling that behavior here by returning false
32+
////////////////////////////////////////////////////////////////////////////////////////////////////////////
33+
return false;
34+
35+
/* TODO remove this commented code and remove all references to this method
2936
let sourceBranch: string = tl.getVariable('build.sourceBranch');
3037
let sccProvider: string = tl.getVariable('build.repository.provider');
3138
@@ -36,6 +43,7 @@ export class VstsServerUtils {
3643
sccProvider.toLowerCase() === "tfsgit" &&
3744
!VstsServerUtils.isNullOrEmpty(sourceBranch) &&
3845
sourceBranch.toLowerCase().startsWith("refs/pull/");
46+
*/
3947
}
4048

4149
/**

Tests-Legacy/L0/Maven/_suite.ts

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,60 +1083,6 @@ describe('Maven Suite', function () {
10831083
});
10841084
});
10851085

1086-
it('Maven with SonarQube - Does not fail if report-task.txt is missing during a PR build', function (done) {
1087-
// Arrange
1088-
createTempDirsForSonarQubeTests();
1089-
var testSrcDir: string = __dirname;
1090-
var testStgDir: string = path.join(__dirname, '_temp');
1091-
createTempDir();
1092-
var codeAnalysisStgDir: string = path.join(testStgDir, '.codeAnalysis'); // overall directory for all tools
1093-
1094-
mockHelper.setResponseAndBuildVars(
1095-
path.join(__dirname, 'response.json'),
1096-
path.join(__dirname, 'new_response.json'),
1097-
[["build.sourceBranch", "refs/pull/6/master"], ["build.repository.provider", "TFSGit"],
1098-
['build.sourcesDirectory', testSrcDir], ['build.artifactStagingDirectory', testStgDir]]);
1099-
var responseJsonFilePath: string = path.join(__dirname, 'new_response.json');
1100-
var responseJsonContent = JSON.parse(fs.readFileSync(responseJsonFilePath, 'utf-8'));
1101-
1102-
// Add fields corresponding to responses for mock filesystem operations for the following paths
1103-
// Staging directories
1104-
responseJsonContent = mockHelper.setupMockResponsesForPaths(responseJsonContent, listFolderContents(testStgDir));
1105-
// Test data files
1106-
responseJsonContent = mockHelper.setupMockResponsesForPaths(responseJsonContent, listFolderContents(testSrcDir));
1107-
1108-
// Write and set the newly-changed response file
1109-
var newResponseFilePath: string = path.join(__dirname, this.test.title + '_response.json');
1110-
fs.writeFileSync(newResponseFilePath, JSON.stringify(responseJsonContent));
1111-
setResponseFile(path.basename(newResponseFilePath));
1112-
1113-
var tr: trm.TaskRunner = setupDefaultMavenTaskRunner();
1114-
tr.setInput('sqAnalysisEnabled', 'true');
1115-
tr.setInput('sqConnectedServiceName', 'ID1');
1116-
1117-
tr.run()
1118-
.then(() => {
1119-
assert(tr.ran('/home/bin/maven/bin/mvn -version'), 'it should have run mvn -version');
1120-
assert(tr.ran(
1121-
'/home/bin/maven/bin/mvn -f pom.xml package -Dsonar.host.url=http://sonarqubeserver:9000 -Dsonar.login=uname -Dsonar.password=pword -Dsonar.analysis.mode=issues -Dsonar.report.export.path=sonar-report.json sonar:sonar'
1122-
), 'it should have run SQ analysis');
1123-
assert(tr.invokedToolCount == 2, 'should have only run maven 2 times');
1124-
assert(tr.resultWasSet, 'task should have set a result');
1125-
assert(tr.stderr.length < 1, 'should not have written to stderr');
1126-
assert(tr.succeeded, 'task should have succeeded');
1127-
1128-
assert(tr.stdout.indexOf('task.addattachment type=Distributedtask.Core.Summary;name=SonarQube Analysis Report') < 1,
1129-
'should not have uploaded a SonarQube Analysis Report build summary');
1130-
done();
1131-
})
1132-
.fail((err) => {
1133-
console.log(tr.stdout);
1134-
console.log(tr.stderr);
1135-
console.log(err);
1136-
done(err);
1137-
});
1138-
});
1139-
11401086
it('Maven build with publish test results', (done) => {
11411087
setResponseFile('response.json');
11421088
var tr = new trm.TaskRunner('Maven', true);
@@ -1770,7 +1716,7 @@ describe('Maven Suite', function () {
17701716
.fail((reason) => done("an error occured: " + reason));
17711717
});
17721718

1773-
it('during PR builds SonarQube analysis runs in issues mode', function (done) {
1719+
it('during PR builds SonarQube analysis runs normally', function (done) {
17741720
// Arrange
17751721
createTempDirsForSonarQubeTests();
17761722
var testSrcDir: string = path.join(__dirname, 'data', 'taskreport-valid');
@@ -1803,7 +1749,7 @@ describe('Maven Suite', function () {
18031749
tr.run()
18041750
.then(() => {
18051751
assert(tr.ran('/home/bin/maven/bin/mvn -version'), 'it should have run mvn -version');
1806-
assert(tr.ran('/home/bin/maven/bin/mvn -f pom.xml package -Dsonar.host.url=http://sonarqubeserver:9000 -Dsonar.login=uname -Dsonar.password=pword -Dsonar.analysis.mode=issues -Dsonar.report.export.path=sonar-report.json sonar:sonar'), 'it should have run SQ analysis in issues mode');
1752+
assert(tr.ran('/home/bin/maven/bin/mvn -f pom.xml package -Dsonar.host.url=http://sonarqubeserver:9000 -Dsonar.login=uname -Dsonar.password=pword sonar:sonar'), 'it should NOT have run SQ analysis in issues mode');
18071753
assert(tr.invokedToolCount == 2, 'should have only run maven 2 times');
18081754
assert(tr.resultWasSet, 'task should have set a result');
18091755
assert(tr.stderr.length == 0, 'should not have written to stderr');

0 commit comments

Comments
 (0)