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