Skip to content
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

Always collect test results after running the build in buildPlugin() and buildPluginWithGradle() #88

Conversation

darxriggs
Copy link
Contributor

This should especially fix test results collection for Gradle, where it's not possible to set test.ignoreFailures from the commandline.

I put this for discussion here as I am not 100% sure if it doesn't brake something in the case of errors. E.g. that archiving is triggered but not working as expected.

@oleg-nenashev
Copy link
Contributor

I am not sur ewhether it is still actual, but there is a massive merge conflict we would need to address

@darxriggs darxriggs force-pushed the fix-gradle-test-results-collection branch from c1dd6c9 to b6bee6c Compare August 13, 2019 18:21
@darxriggs
Copy link
Contributor Author

darxriggs commented Aug 13, 2019

I just fixed the merge conflict. It has been that massive because the indentation changed.

The pull request can be more easily reviewed if ignoring whitespace changes. Only a try/finally was added around the "Build" and "Archive" stages.

@oleg-nenashev
Copy link
Contributor

Ideally we should detach Gradle build to a separate Pipeline step. There are too many things which are not really compatible with Gradle in the new flow, e.g. Jenkins version specifications. It would be better to have a clean buildGradlePlugin() implementation which focuses on https://github.com/jenkinsci/gradle-jpi-plugin. CC @sghill

If someone is interested to migrate Gradle plugins, I am happy to help with implementing the change

@oleg-nenashev
Copy link
Contributor

FTR I tried to do some refactoring in #21 to enable parallelized builds. Some code can be reused, once we solve the autodiscovery problem (requires extra node() stage in the linked PR)

@sghill
Copy link

sghill commented Aug 14, 2019

I don't have a lot of context here, but if this is the original problem:

it's not possible to set test.ignoreFailures from the commandline.

I think you can do this with an initscript that takes a property from the command line. Something like this works:

// init.gradle
allprojects {
    tasks.withType(Test).configureEach {
        it.ignoreFailures = rootProject.findProperty('jenkins.ignoreFailures') ?: false
    }   
}

Running a build with a failing test:

$ ./gradlew -I init.gradle check
> Task :test FAILED
FailsTest > shouldFail FAILED
    java.lang.AssertionError at FailsTest.java:4
1 test completed, 1 failed
[omitted]
BUILD FAILED in 997ms

Same build completed successfully with the property set:

$ ./gradlew -I init.gradle check -Pjenkins.ignoreFailures=true
> Task :test
FailsTest > shouldFail FAILED
    java.lang.AssertionError at FailsTest.java:4
1 test completed, 1 failed
[omitted]
BUILD SUCCESSFUL in 893ms

Ideally we should detach Gradle build to a separate Pipeline step

This seems reasonable to me.

There are too many things which are not really compatible with Gradle in the new flow, e.g. Jenkins version specifications.

Is there a listing of these somewhere I could read through?

@darxriggs
Copy link
Contributor Author

@sghill Yes the original problem was about

it's not possible to set test.ignoreFailures from the commandline.

...and due to it no test results beeing collected on failure.
Therefore I wrapped the stages in a try/finallyconstruct.

@oleg-nenashev I don't have the capacity to extract the Gradle build into a separate build step as suggested by you. This pull request is the only thing I can provide for now.

@oleg-nenashev
Copy link
Contributor

#104

@v1v
Copy link
Contributor

v1v commented Oct 1, 2019

For some reason, I missed this particular PR and I raised another one, which includes the UTs:

testReports = '**/build/test-results/**/*.xml'
}
junit testReports
// TODO do this in a finally-block so we capture all test results even if one branch aborts early
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anymore with this PR:

Suggested change
// TODO do this in a finally-block so we capture all test results even if one branch aborts early

@oleg-nenashev
Copy link
Contributor

Sorry for not handling it. Too many things here and there :(

@darxriggs
Copy link
Contributor Author

@sghill Based on new information from @wolfs I would even go without test.ignoreFailures now because it is not a good idea with respect to the Gradle build cache - see jenkinsci/gradle-plugin#93 (comment).

Copy link
Contributor

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you want to set a flag to prevent the Pipeline from failing on missing reports.

@darxriggs
Copy link
Contributor Author

@v1v You could also follow up on this in your pull request because you already updated the tests.

I think the main question that should be answered is, if the finally block should contain the whole "Archive" stage or only collecting the different test results (JUnit, FindBugs, Checkstyle).

@darxriggs
Copy link
Contributor Author

@oleg-nenashev I guess you are talking about allowEmptyResults (https://jenkins.io/doc/pipeline/steps/junit/). I would not want to add another option because there are already quite a lot. I think the existing skipTests option should already cover the aspect of not having test reports. It can be read as "do not run tests" and/or "do not expect test reports".

This should especially fix test results collection for Gradle,
where it is not possible to set test.ignoreFailures [1] from the
commandline.

[1] https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:ignoreFailures
@darxriggs darxriggs force-pushed the fix-gradle-test-results-collection branch from dd214d4 to b74236d Compare December 27, 2019 15:04
Copy link
Contributor

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the patch. NNote that it will cause regressions in Gradle-based components which have not yet switched to buildPluginWithGradle(). Should we finish the migration first?

@oleg-nenashev oleg-nenashev changed the title Always collect test results Always collect test results after running the build Dec 30, 2019
@oleg-nenashev
Copy link
Contributor

#113
I'm happy to close the above one for the benefit of this one and you can potentially cherry-pick the UTs changes.

Should we also add tests from #113 here? Or do we prefer to do it in a follow-up

@darxriggs darxriggs closed this Dec 30, 2019
@darxriggs darxriggs reopened this Dec 30, 2019
@darxriggs
Copy link
Contributor Author

NNote that it will cause regressions in Gradle-based components which have not yet switched to buildPluginWithGradle()

What kind of regressions do you think of? Maybe I am missing something. The intention was that the new try/finally mechanism always tries to collect the test results, even in case of a failing build or failing tests. So for Gradle-based plugins, if something has been failing before it would still fail, and if nothing has been failing it would still not fail.

@darxriggs
Copy link
Contributor Author

Should we also add tests from #113 here? Or do we prefer to do it in a follow-up

I will have a look, now that I am more familiar with these kind of tests.

@oleg-nenashev
Copy link
Contributor

What kind of regressions do you think of?

No worries, I just misread the code. My apologies

Copy link
Contributor

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with merging it as is, we can do tests in a follow-up if you prefer so @darxriggs @v1v

@darxriggs
Copy link
Contributor Author

@oleg-nenashev Then please already merge it.

I will have to prepare 1 or 2 other pull requests to get the tooling ready for the tests.

@oleg-nenashev oleg-nenashev merged commit 40c5f7d into jenkins-infra:master Dec 31, 2019
@oleg-nenashev oleg-nenashev changed the title Always collect test results after running the build Always collect test results after running the build in buildPlugin() and buildPluginWithGradle() Dec 31, 2019
@darxriggs darxriggs deleted the fix-gradle-test-results-collection branch January 1, 2020 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants