jenkins-spock
jenkins-spock copied to clipboard
jenkins-spock when used with gradle
Summary
This pull requests provides several examples for jenkins-spock when used from gradle.
Checklist
Testing
"N/A - no code changes"
Documentation
"N/A - no code changes"
Not sure if your schedule has eased up or if you have had a chance to further pursue this pull request.
While this works fine in the Gradle build (on CLI), when opening this in IntelliJ (v2020.3.2 CE) I failed to get it working (for a very long time):
- in IntelliJ the tests always failed with something like:
> Task :compileJava NO-SOURCE
> Task :compileGroovy
> Task :processResources NO-SOURCE
> Task :classes
> Task :cleanSharedLibraries
> Task :prepareSharedLibraries
> Task :compileTestJava NO-SOURCE
> Task :compileTestGroovy
> Task :processTestResources UP-TO-DATE
> Task :testClasses
> Task :test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/r.fuereder/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.13/ac054525fdc81cbd0bc2552b57052ebb1a93cd40/groovy-2.5.13.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[2021-02-25 12:01:26,151](Test worker)([]) WARN WholeClasspathPipelineExtensionDetector - Failed to get some classes annotated with [interface hudson.Extension] of type [class org.jenkinsci.plugins.workflow.steps.StepDescriptor] in package [Optional.empty]. For detailed error messages, set the system property PipelineExtensionDetector.expandFailures=true. Failures: [[com.cloudbees.plugins.credentials.cli.CreateCredentialsByXmlCommand, com.cloudbees.plugins.credentials.cli.ImportCredentialsAsXmlCommand, hudson.cli.UpdateNodeCommand, org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$PipelineTimings, hudson.cli.ReloadConfigurationCommand, hudson.cli.DeleteJobCommand, com.cloudbees.plugins.credentials.cli.ListCredentialsProvidersCommand, hudson.cli.ListJobsCommand, com.cloudbees.plugins.credentials.cli.DeleteCredentialsDomainCommand, hudson.cli.DisconnectNodeCommand, hudson.cli.BuildCommand, hudson.cli.GetJobCommand, hudson.cli.DeleteViewCommand, com.cloudbees.plugins.credentials.cli.CreateCredentialsDomainByXmlCommand, com.cloudbees.plugins.credentials.cli.GetCredentialsAsXmlCommand, hudson.cli.ConnectNodeCommand, hudson.cli.VersionCommand, hudson.cli.DeleteNodeCommand, com.cloudbees.plugins.credentials.cli.UpdateCredentialsDomainByXmlCommand, hudson.cli.OnlineNodeCommand, org.jenkinsci.plugins.gitserver.ssh.SshCommandFactoryImpl, hudson.cli.ReloadJobCommand, hudson.cli.InstallPluginCommand, com.cloudbees.plugins.credentials.cli.UpdateCredentialsByXmlCommand, org.jenkinsci.plugins.workflow.cps.CpsThreadDumpAction$PipelineThreadDump, com.cloudbees.plugins.credentials.cli.DeleteCredentialsCommand, hudson.cli.GetNodeCommand, com.cloudbees.plugins.credentials.cli.GetCredentialsDomainAsXmlCommand, com.cloudbees.plugins.credentials.cli.ListCredentialsContextResolversCommand, hudson.cli.CancelQuietDownCommand, hudson.cli.CreateJobCommand, hudson.cli.GetViewCommand, org.jenkinsci.plugins.workflow.cps.replay.ReplayPipelineCommand, hudson.cli.HelpCommand, hudson.cli.SetBuildDisplayNameCommand, hudson.cli.ClearQueueCommand, hudson.cli.SetBuildDescriptionCommand, hudson.cli.GroovyshCommand, hudson.cli.QuietDownCommand, hudson.cli.EnablePluginCommand, com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator, hudson.cli.ConsoleCommand, com.cloudbees.plugins.credentials.casc.SystemCredentialsProviderConfigurator, hudson.cli.WaitNodeOnlineCommand, hudson.cli.GroovyCommand, hudson.cli.WhoAmICommand, hudson.cli.WaitNodeOfflineCommand, hudson.cli.CopyJobCommand, hudson.cli.RemoveJobFromViewCommand, hudson.cli.ListPluginsCommand, jenkins.cli.StopBuildsCommand, hudson.cli.ListChangesCommand, hudson.cli.SessionIdCommand, hudson.cli.CreateNodeCommand, hudson.cli.DeleteBuildsCommand, jenkins.plugins.slack.SlackMatrixBridge, com.cloudbees.plugins.credentials.cli.ListCredentialsCommand, hudson.cli.DisablePluginCommand, hudson.cli.AddJobToViewCommand, hudson.cli.OfflineNodeCommand, hudson.cli.UpdateJobCommand, hudson.cli.CreateViewCommand, com.cloudbees.plugins.credentials.cli.ListCredentialsAsXmlCommand, hudson.cli.UpdateViewCommand]]
[2021-02-25 12:01:29,815](Test worker)([]) WARN WholeClasspathPipelineExtensionDetector - Failed to get some classes annotated with [interface hudson.Extension] of type [class org.jenkinsci.plugins.workflow.cps.GlobalVariable] in package [Optional.empty]. For detailed error messages, set the system property PipelineExtensionDetector.expandFailures=true. Failures: [[com.cloudbees.plugins.credentials.cli.CreateCredentialsByXmlCommand, com.cloudbees.plugins.credentials.cli.ImportCredentialsAsXmlCommand, hudson.cli.UpdateNodeCommand, org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$PipelineTimings, hudson.cli.ReloadConfigurationCommand, hudson.cli.DeleteJobCommand, com.cloudbees.plugins.credentials.cli.ListCredentialsProvidersCommand, hudson.cli.ListJobsCommand, com.cloudbees.plugins.credentials.cli.DeleteCredentialsDomainCommand, hudson.cli.DisconnectNodeCommand, hudson.cli.BuildCommand, hudson.cli.GetJobCommand, hudson.cli.DeleteViewCommand, com.cloudbees.plugins.credentials.cli.CreateCredentialsDomainByXmlCommand, com.cloudbees.plugins.credentials.cli.GetCredentialsAsXmlCommand, hudson.cli.ConnectNodeCommand, hudson.cli.VersionCommand, hudson.cli.DeleteNodeCommand, com.cloudbees.plugins.credentials.cli.UpdateCredentialsDomainByXmlCommand, hudson.cli.OnlineNodeCommand, org.jenkinsci.plugins.gitserver.ssh.SshCommandFactoryImpl, hudson.cli.ReloadJobCommand, hudson.cli.InstallPluginCommand, com.cloudbees.plugins.credentials.cli.UpdateCredentialsByXmlCommand, org.jenkinsci.plugins.workflow.cps.CpsThreadDumpAction$PipelineThreadDump, com.cloudbees.plugins.credentials.cli.DeleteCredentialsCommand, hudson.cli.GetNodeCommand, com.cloudbees.plugins.credentials.cli.GetCredentialsDomainAsXmlCommand, com.cloudbees.plugins.credentials.cli.ListCredentialsContextResolversCommand, hudson.cli.CancelQuietDownCommand, hudson.cli.CreateJobCommand, hudson.cli.GetViewCommand, org.jenkinsci.plugins.workflow.cps.replay.ReplayPipelineCommand, hudson.cli.HelpCommand, hudson.cli.SetBuildDisplayNameCommand, hudson.cli.ClearQueueCommand, hudson.cli.SetBuildDescriptionCommand, hudson.cli.GroovyshCommand, hudson.cli.QuietDownCommand, hudson.cli.EnablePluginCommand, com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator, hudson.cli.ConsoleCommand, com.cloudbees.plugins.credentials.casc.SystemCredentialsProviderConfigurator, hudson.cli.WaitNodeOnlineCommand, hudson.cli.GroovyCommand, hudson.cli.WhoAmICommand, hudson.cli.WaitNodeOfflineCommand, hudson.cli.CopyJobCommand, hudson.cli.RemoveJobFromViewCommand, hudson.cli.ListPluginsCommand, jenkins.cli.StopBuildsCommand, hudson.cli.ListChangesCommand, hudson.cli.SessionIdCommand, hudson.cli.CreateNodeCommand, hudson.cli.DeleteBuildsCommand, jenkins.plugins.slack.SlackMatrixBridge, com.cloudbees.plugins.credentials.cli.ListCredentialsCommand, hudson.cli.DisablePluginCommand, hudson.cli.AddJobToViewCommand, hudson.cli.OfflineNodeCommand, hudson.cli.UpdateJobCommand, hudson.cli.CreateViewCommand, com.cloudbees.plugins.credentials.cli.ListCredentialsAsXmlCommand, hudson.cli.UpdateViewCommand]]
org/jboss/modules/ModuleLoadException
java.lang.NoClassDefFoundError: org/jboss/modules/ModuleLoadException
at java.base/java.lang.Class.forName(Class.java:315)
at com.homeaway.devtools.jenkins.testing.LocalProjectPipelineExtensionDetector.getClassesOfTypeInPackage(LocalProjectPipelineExtensionDetector.java:88)
at com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification.setupSpec(JenkinsPipelineSpecification.groovy:1122)
Caused by: java.lang.ClassNotFoundException: org.jboss.modules.ModuleLoadException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 3 more
DeployerSpec > classMethod FAILED
java.lang.NoClassDefFoundError at Class.java:315
Caused by: java.lang.ClassNotFoundException at BuiltinClassLoader.java:581
1 test completed, 1 failed
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///C:/Users/r.fuereder/Documents/TK-QS/Research-Pipeline-unit-testing/jenkins-spock-PR67/examples/shared-library-gradle/build/reports/tests/test/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 21s
6 actionable tasks: 5 executed, 1 up-to-date
It started working when I replaced the usage of Gradle plugin "org.jenkins-ci.jpi":
plugins {
...
// Apply Gradle JPI plugin to simplify dependency management
//id 'org.jenkins-ci.jpi' version '0.39.0' // !!!
}
... AND the Jenkins plugin dependencies:
// provides stage() step
// testImplementation 'org.jenkins-ci.plugins:pipeline-stage-step:2.5' // !!!
// provides isUnix() step
// testImplementation 'org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.23' // !!!
// provides sh() step
// testImplementation 'org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.36' // !!!
// provides libraryResource() step
// testImplementation 'org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.17' // !!!
// provides slackSend() step
// testImplementation 'org.jenkins-ci.plugins:slack:2.43' // !!!
// provides sshagent() step
// testImplementation 'org.jenkins-ci.plugins:ssh-agent:1.20' // !!!
... with more or less something like this (mind the ugly/tedious transitive dependencies and "@jar" plugin file extension "hint"):
testImplementation 'org.jenkins-ci.plugins:pipeline-stage-step:2.5@jar'
// provides isUnix() step
testImplementation 'org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.23@jar'
// provides sh() step
testImplementation 'org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.36@jar'
// provides libraryResource() step
testImplementation 'org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.17@jar'
// provides slackSend() step
testImplementation 'org.jenkins-ci.plugins:slack:2.43@jar'
// provides sshagent() step
testImplementation 'org.jenkins-ci.plugins:ssh-agent:1.20@jar'
testImplementation 'org.jenkins-ci.plugins:durable-task:1.35@jar'
testImplementation 'org.jenkins-ci.plugins:timestamper:1.11.8@jar'
testImplementation 'org.jenkins-ci.plugins:ws-cleanup:0.37@jar'
testImplementation 'org.jenkins-ci:symbol-annotation:1.22@jar'
testImplementation 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.23@jar'
testImplementation 'org.jenkins-ci.plugins.workflow:workflow-cps:2.87@jar'
testImplementation 'org.jenkins-ci.plugins.workflow:workflow-api:2.41@jar'
// // Für sshagent:
// // workflow-step-api:2.16,bouncycastle-api:2.16.3,credentials:2.1.17,ssh-credentials:1.14
testImplementation 'org.jenkins-ci.plugins:bouncycastle-api:2.16.3@jar'
testImplementation 'org.jenkins-ci.plugins:credentials:2.3.13@jar'
testImplementation 'org.jenkins-ci.plugins:ssh-credentials:1.14@jar'
testImplementation 'org.jenkins-ci.plugins.workflow:workflow-support:3.5@jar'
testImplementation 'org.jenkins-ci.plugins.workflow:workflow-scm-step:2.4@jar'
testImplementation 'org.jenkins-ci.plugins:script-security:1.74@jar'
testImplementation 'org.jenkins-ci.plugins:scm-api:2.6.3@jar'
testImplementation 'org.jenkins-ci.plugins:structs:1.20@jar'
testImplementation 'org.jenkins-ci.plugins:cloudbees-folder:6.11.1@jar'
testImplementation 'org.apache.ivy:ivy:2.4.0'
testImplementation 'com.cloudbees:groovy-cps:1.32'
testImplementation 'org.jenkins-ci.plugins:git-server:1.9@jar'
testImplementation 'org.jenkins-ci.plugins:git-client:2.7.6@jar'
testImplementation 'org.jenkins-ci.plugins:jsch:0.1.54.1@jar'
testImplementation 'com.jcraft:jsch:0.1.54'
testImplementation 'org.jenkins-ci.plugins:apache-httpcomponents-client-4-api:4.5.10-2.0@jar'
(Not sure if really all of them are needed though)
Does that make sense!? (Because IntelliJ by default uses Gradle for test execution too, for some time being.) How are you executing tests (without Gradle) or in which IDE?
Hm, my problem looks very related to #89
@reinholdfuereder : I could never get the Gradle tests to work in IntelliJ, so I cheated and manually created jUnit tests
@awittha : any progress on merging this pull request?
@reinholdfuereder : I could never get the Gradle tests to work in IntelliJ, so I cheated and manually created jUnit tests
Thanks for the "outing" ;-)
(I think besides the aforementioned "manual transitive dependency resolution" approach, IIRC switching to Java 8 -- as mentioned by @wheelerlaw in #89 -- also helped me; and maybe/presumably #90 might be the actual -- by comparison really easy -- final solution according to @wheelerlaw)
@reinholdfuereder : I went back to my IntelliJ project and ran a Gradle test and it ran fine with Gradle this time.
What is your Project SDK?
And what is your Gradle JVM?
As I tried to convey it failed initially (with Java 11) and succeeded when switching to Java 8 (inspired on the aforementioned #89 and #90). And IIRC in shell Gradle CLI succeeded right away, because there Java 8 was default.
Gotcha. Thanks for the explanation.
Happy birthday to the pull request (opened 1 year ago).
Happy birthday to the pull request (opened 1 year ago).
I think this project is dead.
@corporate-gadfly Thanks for the work, works great for me.
@atopuzov 👍
Hello, all. Some version bumps in latest commit.
Happy new year! Some more version bumps in latest commits.
Happy two year anniversary (opened 2 years ago).