diff --git a/docs/Home.md b/docs/Home.md index 03aff3467..b78652756 100644 --- a/docs/Home.md +++ b/docs/Home.md @@ -39,6 +39,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins * Fixed support for the [Static Code Analysis Plugins](https://wiki.jenkins-ci.org/display/JENKINS/Static+Code+Analysis+Plug-ins) ([#724](https://github.com/jenkinsci/job-dsl-plugin/pull/724)) + * Fixed support for scripts in directories when using the command line runner + ([#740](https://github.com/jenkinsci/job-dsl-plugin/pull/740)) * Built-in support for the [GitHub Pull Request Builder Plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin) is deprecated, see [Migration](Migration#migrating-to-143) diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/DslScriptLoader.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/DslScriptLoader.groovy index 6756a9be6..21ea4a05e 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/DslScriptLoader.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/DslScriptLoader.groovy @@ -86,8 +86,9 @@ class DslScriptLoader { } private static boolean isValidScriptName(String scriptFile) { - int idx = scriptFile.lastIndexOf('.') - String normalizedName = idx > -1 ? scriptFile[0..idx - 1] : scriptFile + String fileName = new File(scriptFile).name + int idx = fileName.lastIndexOf('.') + String normalizedName = idx > -1 ? fileName[0..idx - 1] : fileName if (normalizedName.length() == 0 || !Character.isJavaIdentifierStart(normalizedName.charAt(0))) { return false } diff --git a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/DslScriptLoaderSpec.groovy b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/DslScriptLoaderSpec.groovy index 9af30531b..a1f315ba2 100644 --- a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/DslScriptLoaderSpec.groovy +++ b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/DslScriptLoaderSpec.groovy @@ -235,6 +235,17 @@ folder('folder-b') { e.message =~ /test-script\.dsl/ } + def 'script in directory'() { + setup: + ScriptRequest request = new ScriptRequest('foo/test.dsl', null, resourcesDir, false) + + when: + DslScriptLoader.runDslEngine(request, jm) + + then: + noExceptionThrown() + } + def 'script with method'() { setup: ScriptRequest request = new ScriptRequest( diff --git a/job-dsl-core/src/test/resources/foo/test.dsl b/job-dsl-core/src/test/resources/foo/test.dsl new file mode 100644 index 000000000..912055b81 --- /dev/null +++ b/job-dsl-core/src/test/resources/foo/test.dsl @@ -0,0 +1,2 @@ +job('test') { +}