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

jenkins-spock when used with gradle #67

Open
wants to merge 48 commits into
base: master
Choose a base branch
from

Conversation

corporate-gadfly
Copy link

@corporate-gadfly corporate-gadfly commented Apr 7, 2020

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"

@corporate-gadfly corporate-gadfly mentioned this pull request Apr 7, 2020
- TODO:
  - 2 out of 5 tests are failing
  - logdir_IS_UNDEFINED is being created, presumably because logback
    configuration is not kicking in
- transitive dependencies are grabbed by plugin
  - take out unnecessary org.jenkins-ci.plugins dependencies
  - take out @jar notation
allow getSharedLibraryVariables() to find .groovy scripts in classpath under "vars"
@corporate-gadfly corporate-gadfly changed the title minimal example for jenkins-spock used from gradle jenkins-spock when used with gradle Apr 22, 2020
@awittha awittha self-assigned this May 28, 2020
@corporate-gadfly
Copy link
Author

Not sure if your schedule has eased up or if you have had a chance to further pursue this pull request.

@reinholdfuereder
Copy link

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?

@reinholdfuereder
Copy link

Hm, my problem looks very related to #89

@corporate-gadfly
Copy link
Author

@reinholdfuereder : I could never get the Gradle tests to work in IntelliJ, so I cheated and manually created jUnit tests
image

- version bump for jenkins-spock to 2.1.5
- version bump for jenkins-core to 2.291
- version bump for workflow-cps-global-lib to 2.19
@atopuzov
Copy link

@corporate-gadfly Thanks for the work, works great for me.

@corporate-gadfly
Copy link
Author

@atopuzov 👍

- version bump for jenkins-core to 2.316
- version bump for groovy-all to 2.5.15
- version bump for logback to 1.2.6
- version bump for workflow-cps to 2.94
- version bump for workflow-durable-task-step to 2.40
@corporate-gadfly
Copy link
Author

Hello, all. Some version bumps in latest commit.

- version bump for jenkins to 2.329
- version bump for logback to 1.2.10
- version bump for slack to 2.49
@corporate-gadfly
Copy link
Author

Happy new year! Some more version bumps in latest commits.

- version bump for jenkins-core to 2.335
- version bump for workflow-cps to 2.94.1
- version bump for ssh-agent to 1.24.1
- version bump for workflow-cps-global-lib to 2.21.1
- version bump for jenkins-core to 2.340
- version bump for groovy-all to 2.5.16
- version bump for logback to 1.2.11
- version bump for groovy-cps to 1.32
@corporate-gadfly
Copy link
Author

Happy two year anniversary (opened 2 years ago).

corporate-gadfly and others added 2 commits June 20, 2022 16:01
- jenkins-core to 2.340
- groovy-all to 2.5.17
- workflow-cps to 2725.v7b_c717eb_12ce
- workflow-basic-steps to 948.v2c72a_091b_b_68
- workflow-durable-task-step to 1146.v1a_d2e603f929
- ssh-agent to 295.v9ca_a_1c7cc3a_a_
- pipeline-stage-step to 293.v200037eefcd5
- workflow-cps-global-lib to 588.v576c103a_ff86
- slack to 608.v19e3b_44b_b_9ff
@pablogrs
Copy link

how can I run your branch in a project @corporate-gadfly?
thank you for the work

@corporate-gadfly
Copy link
Author

@pablogrs : Thanks for the kind words.

Assuming you have a gradle project, you can find 3 gradle examples in my fork. Here's a link to one example. And here is a link to a specific test.

@yx135790
Copy link

yx135790 commented Sep 15, 2023

I have encountered the this Exeaption that was mentioned in you branch.
Renaming the test Class did work, thanks for the big help. Do you have any ideas or background why this is happening ?
java.lang.NoClassDefFoundError: active (wrong name: Active)

@pablogrs
Copy link

I created yet another fork for it
https://github.com/pablogrs/jenkins-spock
and ended up using in Gradle with https://jitpack.io/#pablogrs/jenkins-spock to make it work with Java 11

@corporate-gadfly
Copy link
Author

That's a good find @pablogrs .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants