-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix Maven task rebuild when using jacoco for code coverage #21472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| const verifyOrLaterPhases = ['verify', 'install', 'deploy']; | ||
| const hasVerifyOrLater = mavenGoals.some(goal => verifyOrLaterPhases.includes(goal.toLowerCase())); | ||
|
|
||
| if (!hasVerifyOrLater) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if the user input in goals property has verify or a later phase as this will eventually execute verify phase.
If not, append verify argument to mvn command.
As per https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#default-lifecycle, install and deploy phases come after verify phase.
Since maven executes all the phases in sequential order upto the specified phase, adding verify to maven run command will not be needed if a later phase is already given as input.
| } | ||
| mvnRun.arg(mavenGoals); | ||
|
|
||
| if (tl.getPipelineFeature('RemoveDuplicateMavenRun') && isCodeCoverageOpted && ccTool.toLowerCase() === "jacoco") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running maven upto verify phase is needed only when jacoco is selected as code coverage - tool.
| mvnReport.arg("verify"); |
If jacoco is not selected as code coverage tool, flow will be as earlier and adding verify will not be required.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| sendCodeCoverageEmptyMsg(); | ||
| defer.reject(err); | ||
| }); | ||
| if (tl.getPipelineFeature('RemoveDuplicateMavenRun')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove maven execution if FF is enabled. The flow for both jacoco and cobertura code coverage tools will remain same in this case.
| assert(testRunner.ran('/home/bin/maven/bin/mvn -f pom.xml help:effective-pom'), 'it should have generated effective pom'); | ||
| assert(testRunner.ran('/home/bin/maven/bin/mvn -f pom.xml clean package'), 'it should have run mvn -f pom.xml package'); | ||
| if (tl.getPipelineFeature('RemoveDuplicateMavenRun')){ | ||
| assert(testRunner.ran('/home/bin/maven/bin/mvn -f pom.xml clean verify'), 'it should have run mvn -f pom.xml verify'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goals property has package as input in the task setup. The code coverage tool selected is JaCoCo.
| goals: 'package', |
In this case, verify will be appended to maven command as it executes after package phase as per Maven's build lifecycle - https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#default-lifecycle.
| if (tl.getPipelineFeature('RemoveDuplicateMavenRun')){ | ||
| assert(testRunner.ran('/home/bin/maven/bin/mvn -f pom.xml clean verify'), 'it should have run mvn -f pom.xml verify'); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this tested ? what is the mechanism to enable flag for L0 as this does not run in pieline the tl.getPipelineFeature('RemoveDuplicateMavenRun') will always be false ?
I think we need 1 test with FF disabled and 1 with enabled.
Context
Describe the context or motivation for this PR. Include links to any related Azure DevOps Work Items or GitHub issues.
📌 Associated WI: AB#2327840
Task Name
MavenV4
Description
Remove second maven run(during code coverage publishing step) to avoid running maven lifecycle phases twice.
The second adds verify phase when JaCoCo is selected as the code coverage -
azure-pipelines-tasks/Tasks/MavenV4/maventask.ts
Line 460 in 54f548f
This is because JaCoCo plugin binds its check goal to the Maven verify phase, which ensures that all tests have run and their coverage data is available - #6458 (comment).
This PR combines below 2 maven runs adding verify phase to the first run:
run to execute maven goals:
azure-pipelines-tasks/Tasks/MavenV4/maventask.ts
Line 268 in 54f548f
maven run before publishing code coverage:
azure-pipelines-tasks/Tasks/MavenV4/maventask.ts
Line 462 in 54f548f
Risk Assessment (Low / Medium / High)
Low. Changes covered under feature flag
Change Behind Feature Flag (Yes / No)
Yes
Tech Design / Approach
Documentation Changes Required (Yes/No)
Indicate whether related documentation needs to be updated.
Unit Tests Added or Updated (Yes / No)
Indicate whether unit tests were added or modified to reflect these changes.
Additional Testing Performed
canary test pipeline runs:
FF enabled - Pipelines - Run 20251125.8
FF disabled - Pipelines - Run 20251125.7
Logging Added/Updated (Yes/No)
Telemetry Added/Updated (Yes/No)
Rollback Scenario and Process (Yes/No)
Dependency Impact Assessed and Regression Tested (Yes/No)
Checklist