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

Cannot run inline script when shared library is loaded #472

Open
grzegorzgrzegorz opened this issue Jan 11, 2022 · 9 comments
Open

Cannot run inline script when shared library is loaded #472

grzegorzgrzegorz opened this issue Jan 11, 2022 · 9 comments

Comments

@grzegorzgrzegorz
Copy link

grzegorzgrzegorz commented Jan 11, 2022

Jenkins and plugins versions report

Environment
Paste the output here

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

Windows

Reproduction steps

Unable to run this test:

import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Before
import org.junit.Test

import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource

class TestingExamplesFromGithub extends BasePipelineTest {

    @Override
    @Before
    void setUp() throws Exception {
        super.setUp()

        def library = library().name('commons')
                .defaultVersion('<notNeeded>')
                .allowOverride(true)
                .implicit(true)
                .targetPath('<notNeeded>')
                .retriever(projectSource())
                .build()
        helper.registerSharedLibrary(library)
    }

    @Test
    void testSomeScript() throws Exception {
        def script = runInlineScript('''
            node {
                stage('Build') {
                    echo 'make'
                }
            }
        ''')


        printCallStack()
        assertJobStatusSuccess()
    }

}

Expected Results

Test is run, stack is displayed, assertion is made.

Actual Results

Test is hanging.

Anything else?

When library is not loaded, the test can be executed successfully.

@grzegorzgrzegorz
Copy link
Author

grzegorzgrzegorz commented Feb 4, 2022

What is this play with "bug" label about? Should it not be used at all? Could you explain it @nre-ableton ?

@nre-ableton
Copy link
Contributor

I removed all labels except for "dependabot", which gets added automatically by the dependabot service by GitHub and can't be avoided. The labels weren't useful and just cluttered up the backlog.

@turboBasic
Copy link

I have encountered the same problem. Test which uses runScript('...') or runInlineScript('...') fails when library is loaded

@jiridanek
Copy link

I have one suggestion. Check the groovy version you have on your classpath. It should be

implementation('org.codehaus.groovy:groovy-all:2.4.21')

That's first because this ancient version is what Jenkins actually uses, and second, when I used 3.0.12, I saw a deadlock when loading a shared library, when the test was trying to compile the groovy. Also, this is what JenkinsPipelineUnit tests with.

JenkinsPipelineUnit has self tests for inlineScript functionality, https://github.com/RecuencoJones/JenkinsPipelineUnit/blob/master/src/test/groovy/com/lesfurets/jenkins/TestInlineScript.groovy so it is unlikely this will simply completely break.

@jiridanek
Copy link

jiridanek commented Mar 20, 2024

One more note, are you using Java 11 when running tests? I found that (with groovy 3.0.13) the tests run on java 11 and get stuck the way described in this issue on 17. My colleagues were perfectly happy with that version of groovy and java 11 and after I downgraded to 11, I am happy too.

@axieum
Copy link
Contributor

axieum commented Jul 22, 2024

I am also experiencing this deadlock you mentioned when compiling the groovy from the shared library.

If I downgrade to Groovy 2.4.21, I get -

Unable to load class jenkins.model.Jenkins due to missing dependency javax/servlet/ServletException

which appears to only exist in the Java EE (enterprise edition), which I haven't look at how to install yet.

If I downgrade to Java 11, I get -

org/kohsuke/stapler/CaptureParameterNameTransformation has been compiled by a more recent version of the Java Runtime (class file version 61.0)

which means the org.kohsuke.stapler:stapler:1881.vd39f3ee5c629@jar dependency requires at least Java 17 to run.

@axieum
Copy link
Contributor

axieum commented Jul 22, 2024

I have
PipelineBase.groovy

abstract class PipelineBase implements Serializable {
    // ...
}

GradlePipeline

class GradlePipeline extends PipelineBase {
    // ...
}

If I remove the extends PipelineBase from the GradlePipeline class (making it self-contained), then Groovy 3.0.21 and Java 21 are able to run the tests successfully, but with the extends, it deadlocks and I can see the thread is paused on acquiring a file lock.

@jiridanek
Copy link

jiridanek commented Jul 22, 2024

Unable to load class jenkins.model.Jenkins due to missing dependency javax/servlet/ServletException

I have org.jenkins-ci.main:jenkins-core:2.440.2 on the classpath, and that brings in jakarta servlet jar as a transitive dependency. Something similar to https://github.com/nemerosa/ontrack-jenkins-cli-pipeline/blob/main/build.gradle.kts#L36.

@axieum
Copy link
Contributor

axieum commented Jul 23, 2024

Amazing, upgrading jenkins-core fixed the missing javax/servlet dependency - thank you! 🙌

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

5 participants