Skip to content

Commit f743063

Browse files
committed
Merge branch 'JENKINS-53840'
2 parents d003e77 + 60125b6 commit f743063

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/Home.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
3333

3434
## Release Notes
3535
* 1.77 (unreleased)
36+
* Fixed problem with paths on Windows
37+
([JENKINS-53840](https://issues.jenkins-ci.org/browse/JENKINS-53840))
3638
* 1.76 (August 22 2019)
3739
* Added documentation for pitfalls when using multiple Job DSL build steps in a single job
3840
([JENKINS-44142](https://issues.jenkins-ci.org/browse/JENKINS-44142))

job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/ScriptRequestGenerator.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ScriptRequestGenerator implements Closeable {
7070
@PackageScope
7171
static String getAbsolutePath(FilePath filePath) {
7272
// see JENKINS-33723
73-
filePath.getRemote()
73+
FilenameUtils.normalize(filePath.getRemote(), true)
7474
}
7575

7676
private URL createClasspathURL(FilePath filePath) {
@@ -96,7 +96,6 @@ class ScriptRequestGenerator implements Closeable {
9696

9797
private URL createWorkspaceUrl(FilePath filePath) {
9898
String relativePath = getAbsolutePath(filePath) - getAbsolutePath(workspace)
99-
relativePath = relativePath.replaceAll('\\\\', '/') // normalize for Windows
10099
String slash = filePath.directory ? '/' : ''
101100
new URL(createWorkspaceUrl(), "$relativePath$slash")
102101
}

job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/ScriptRequestGeneratorSpec.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import javaposse.jobdsl.dsl.DslException
88
import javaposse.jobdsl.dsl.ScriptRequest
99
import org.junit.ClassRule
1010
import org.jvnet.hudson.test.JenkinsRule
11+
import hudson.FilePath
12+
import spock.lang.Requires
1113
import spock.lang.Shared
1214
import spock.lang.Specification
1315
import spock.lang.Unroll
@@ -402,4 +404,26 @@ class ScriptRequestGeneratorSpec extends Specification {
402404
then:
403405
requests.empty
404406
}
407+
408+
@Requires({ os.isWindows() })
409+
def 'allow differing separators in base path of workspace and target (on Windows)'() {
410+
setup:
411+
EnvVars env = new EnvVars()
412+
// input a workspace that has forward slash separators where the target will get backward slashes
413+
String crookedRemote = build.workspace.remote.replace('\\', '/')
414+
FilePath customWorkspace = new FilePath(new FilePath(new File('')), crookedRemote)
415+
ScriptRequestGenerator generator = new ScriptRequestGenerator(customWorkspace, env)
416+
417+
when:
418+
List<ScriptRequest> requests = generator.getScriptRequests('a.groovy', false, null, false, null).toList()
419+
420+
then:
421+
requests.size() == 1
422+
requests[0].body == SCRIPT_A
423+
requests[0].urlRoots.length == 1
424+
requests[0].urlRoots[0].toString() == 'workspace:/'
425+
!requests[0].ignoreExisting
426+
requests[0].scriptPath == getAbsolutePath(build.workspace.child('a.groovy'))
427+
requests[0].relativeScriptPath == 'a.groovy'
428+
}
405429
}

0 commit comments

Comments
 (0)