JenkinsPipelineUnit icon indicating copy to clipboard operation
JenkinsPipelineUnit copied to clipboard

Race condition with multiple Global Libraries?

Open raoel opened this issue 7 years ago • 1 comments

I added a questionmark behind the topic, because I am not sure what happens.

We have a pipeline to create a build for technology X; since we are DRY we have a CORE-pipeline that contains shared bits of code that are used for all technologies.

This is in the @before of my Unittest class:

helper.registerSharedLibrary(library('pipeline-core')
                .retriever(GitSource.gitSource('https://something/core'))
                .targetPath(coreFolder.path)
                .defaultVersion("master")
                .allowOverride(true)
                .implicit(false)
                .build())

helper.registerSharedLibrary(library('pipeline-X')
                .retriever(GitSource.gitSource('https://something/X'))
                .targetPath(coreFolder.path)
                .defaultVersion("master")
                .allowOverride(true)
                .implicit(false)
                .build())

And then the test itself:

def script = loadScript("src/main/jenkins/pipeline.jenkins")

printCallStack()

pipeline.jenkins looks like this:

@Library(['pipeline-core','pipeline-X']) _
runPipelineFromX()

Now each time I run, one of these happens:

  • the @Library call fails, saying that it cannot load both pipeline-core and pipeline-X
  • It cannot find a number of dependencies of pipeline-X, all of these dependencies are part of pipeline-core
  • it starts running the pipeline and fails on one of the lines in there

The 3rd option is expected (I am still working on the mocking/binding) The 1st option tells me sometimes the libraries are not done with loading The 2nd option tells me that pipeline-X is loaded but pipeline-core was not finished yet

So my questions:

  • to me this looks like a race-condition, because the effect are random. Am I right? Is this related to multiple shared libraries?
  • If so: is there a way to tell the unittest to wait until both libraries are loaded? I am quite new in the world of Java, and I have read your code but I couldn't find a way to do this.

raoel avatar Aug 01 '17 12:08 raoel

That's a tricky one.

There is no reason for a race condition, but I'll look into it.

Starting from the version 1.1 of the framework you can separate the load and run with

Script script = loadScript('my-pipeline.jenkins')
runScript(script)

But I doubt that it is a timing issue.

ozangunalp avatar Aug 30 '17 20:08 ozangunalp