Exception for custom job workspace location on Windows

36 views
Skip to first unread message

Alexander Röhnsch

unread,
Aug 13, 2019, 9:28:29 AM8/13/19
to job-dsl-plugin
Hi,

I'm trying to move my current jobDSL build step implementation from an in-config script to a file in my repository, e.g. in the form of "some/path/myscript.groovy". It checks out and the file does exist in the workspace.

However, when the job execution comes up to the build step, it fails with this exception:

FATAL: unknown protocol: c
java.net.MalformedURLException: unknown protocol: c
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:255)
    at javaposse.jobdsl.plugin.ScriptRequestGenerator.createWorkspaceUrl(ScriptRequestGenerator.groovy:101)
    [...]

This is jobDSL 1.74, on Jenkins 2.187, running on Windows. The job ("foo") uses a custom workspace location, e.g. "C:\jenkins_work\${JOB_NAME}", and also, the job is organized in a folder, e.g. "myfolder", as provided by the Jenkins Folder plugin. For some reason, in this circumstance, JOB_NAME happens to contain a forward slash (probably put there by the folder plugin), thus rendering the workspace to "C:\jenkins_work\myfolder/foo".

This trips up the relativePath calculation in ScriptRequestGenerator.createWorkspaceUrl, because filePath and workspace come out with different separators in their common base path. With this mismatch, relativePath actually yields an absolute path (starting C:/), triggering the above exception from the URL constructor.

I propose fixing this in the jobDSL plugin, because users are free to enter any weird separator mashup for custom workspace locations (on Windows), and it needs to be normalized only for calculating relative paths.

For some reason, filePath is already normalized to Windows separators. Therefore I guess it should be sufficient to change:

> String relativePath = getAbsolutePath(filePath) - getAbsolutePath(workspace)

to this:

> String relativePath = getAbsolutePath(filePath) - FilenameUtils.normalize(getAbsolutePath(workspace))

in ScriptRequestGenerator.createWorkspaceUrl.

What do you think?

Kind regards
Alexander Röhnsch

Daniel Spilker

unread,
Aug 19, 2019, 10:07:17 AM8/19/19
to job-dsl...@googlegroups.com
Hi Alexander,

thanks for analyzing the problem. This has been reported as JENKINS-53840.

Can you open a pull request that contains the proposed fix along with a unit test that reproduces the problem?

Regards,
Daniel




--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/3c55d428-b673-4d4a-b152-a1382ee031c0%40googlegroups.com.

Alex R

unread,
Aug 21, 2019, 5:50:41 AM8/21/19
to job-dsl...@googlegroups.com
Hi Daniel,
I can certainly open a pull request. For a unit test, there is ScriptRequestGeneratorSpec, but I think it unwise to configure a custom workspace in its central setupSpec(). Would it be sufficient to write a unit test for just ScriptRequestGenerator.createWorkspaceUrl?

Regards,
Alexander

Daniel Spilker

unread,
Aug 21, 2019, 8:00:52 AM8/21/19
to job-dsl...@googlegroups.com
Hi Alex,

yes, do not configure a custom workspace in setupSpec(). The createWorkspaceUrl methods is private and should stay private, so it can not be tested directly. I suggest to add a test to ScriptRequestGeneratorSpec that creates a new job/build with a custom workspace and ignores the job/build that is setup by setupSpec().

Open a pull request and we discuss the code on GitHub.

Regards,
Daniel


Alex R

unread,
Aug 22, 2019, 8:06:41 AM8/22/19
to job-dsl...@googlegroups.com
Hi Daniel,

I created a pull request.

Regards,
Alex

Reply all
Reply to author
Forward
0 new messages