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

Compatibility with Groovy 4 #521

Open
andrefmarques opened this issue Apr 26, 2022 · 16 comments
Open

Compatibility with Groovy 4 #521

andrefmarques opened this issue Apr 26, 2022 · 16 comments

Comments

@andrefmarques
Copy link

andrefmarques commented Apr 26, 2022

Jenkins and plugins versions report

Environment
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>jenkins-pipeline-testing</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>jenkins-ci-releases</id>
            <url>https://repo.jenkins-ci.org/releases/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>4.0.0</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.lesfurets</groupId>
            <artifactId>jenkins-pipeline-unit</artifactId>
            <version>1.14</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.13.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.groovy</groupId>
                        <artifactId>groovy</artifactId>
                        <version>4.0.0</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
                <configuration>
                    <scripts>
                        <script>src/main/groovy/Main.groovy</script>
                    </scripts>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

</project>

What Operating System are you using (both controller, and any agents involved in the problem)?

Fedora 36
java 1.8.0_302

Reproduction steps

I'm trying to run a DeclarativePipelineTest, file is TestDecExample.groovy

import org.junit.Before
import org.junit.Test
import com.lesfurets.jenkins.unit.declarative.*

class TestDecExample extends DeclarativePipelineTest {
    // Setup environment for running unit tests
    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp()
    }

    @Test
    public void should_execute_without_errors() throws Exception {
        def script = loadScript("Jenkinsfile")
        script.execute()
        assertJobStatusSuccess()
        printCallStack()
    }
}

The Jenkins file is:

pipeline {
    agent none
    stages {
        stage('Example Build') {
            agent { docker 'maven:3-alpine' }
            steps {
                echo 'Hello, Maven'
                sh 'mvn --version'
            }
        }
        stage('Example Test') {
            agent { docker 'openjdk:8-jre' }
            steps {
                echo 'Hello, JDK'
                sh 'java -version'
            }
        }
    }
}

Then I run mvn test, same results with executing the test via Intellij

Expected Results

The test runs and prints if it is successful or not.

Actual Results

groovy.lang.MissingMethodException: No signature of method: com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest.setUp() is applicable for argument types: () values: []
Possible solutions: setUp(), setUp(), getAt(java.lang.String), tap(groovy.lang.Closure), sleep(long), sleep(long, groovy.lang.Closure)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:72)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:148)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:166)
	at com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest.setUp(DeclarativePipelineTest.groovy:17)
	at TestDecExample.super$3$setUp(TestDecExample.groovy)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
	at groovy.lang.MetaClassImpl.doInvokeMethod(MetaClassImpl.java:1369)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1103)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:146)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:166)
	at TestDecExample.setUp(TestDecExample.groovy:10)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
	```

### Anything else?

_No response_
@nre-ableton
Copy link
Contributor

I just tried to reproduce locally by copy/pasting your files into a new, empty project. It worked fine for me, using Ubuntu-ish Linux 21.10 and OpenJDK 1.8.0_312.

@andrefmarques
Copy link
Author

With the same pom.xml?

@nre-ableton
Copy link
Contributor

@andrefmarques Yep, copy pasted from the "details" part of the issue description above.

@andrefmarques
Copy link
Author

I've tried on Lubuntu 22.04 and got the same issue.
BasePipelineTest and BaseRegressionTest are working as expected.
Any idea where to look for the cause of this?

@nre-ableton
Copy link
Contributor

Sadly, I'm not certain. I don't use the declarative API for pipelines myself and am not terribly familiar with these test classes.

If you like, I can upload a tarball of the example project based on your above code, just as a sanity check. Would that be useful @andrefmarques ?

@andrefmarques
Copy link
Author

Yes, that would be great!

@nre-ableton
Copy link
Contributor

Ok, here's my test project: test-project-thingy.tar.gz

@grzegorzgrzegorz
Copy link

@andrefmarques just do not use Groovy 4. It is GroovyObjectHelper class which fails and which is introduced in version 4.

@nre-ableton nre-ableton changed the title Unable to run DeclarativePipelineTest Compatibility with Groovy 4 Jun 30, 2022
@nre-ableton
Copy link
Contributor

@grzegorzgrzegorz is right, this is probably a Groovy 4 issue. I've renamed this issue accordingly.

@gulyas-istvan-netlock-hu

I am testing with Groovy 3.0.11 and everything works well.

@meelistolk
Copy link

Please add a note to the Readme file to specifically state that JenkinsPipelineUnit is not compatible with Groovy 4

@nre-ableton
Copy link
Contributor

@meelistolk Done, see #575

@meelistolk
Copy link

Excellent!
I wish this had been there a few days ago, would have saved me a few days of troubleshooting and debugging :)

@nre-ableton
Copy link
Contributor

Excellent! I wish this had been there a few days ago, would have saved me a few days of troubleshooting and debugging :)

Sorry about that. 😅

@jacekgajek
Copy link

Hey is there any progress in this issue?
I had to rewrite quite a lot of code today because I'm new to jenkins pipelines and was surprised it couldn't compile switch expressions.

@nre-ableton
Copy link
Contributor

Hey is there any progress in this issue?

I had to rewrite quite a lot of code today because I'm new to jenkins pipelines and was surprised it couldn't compile switch expressions.

On this issue, sorry, no. I can't speak for Jenkins itself, though. Last time I checked Jenkins still shipped with Groovy 2.4.

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

No branches or pull requests

6 participants