Search code examples
jenkinsjenkins-pluginsdsljenkins-build-flow

Read DSL from file in Jenkins outside of workspace


I know its possible to run a .dsl file from an external source instead of just writing the code of the flow in the job's description, but every time I try to run lets say:

/home/flows/flow_script.dsl

I get the following error:

java.io.FileNotFoundException:/home/flows/flow_script.dsl (No such file or directory)

The path is correct, I can see the file through that path from the shell, but it doesnt let me select anything outside the "builds workspace" apparetly.


Solution

  • I recently ran into this very issue: my DSL script was outside of my workspace (installed via a package). The problem is that the DSL Scripts path is an Ant format that only allows specific patterns (and not absolute paths).

    My workaround is hacky, but it did work: add an Execute Shell step before the "Process Job DSLs" step that symlinks the external directory into the workspace.

    Something like this:

    echo "Creating a symlink from /home/flows to workspace"
    ln -sf "/home/flows" .flows
    

    Then you can set the DSL Scripts path to ".flows/flow_script.dsl".

    This has some additional caveats, of course: the directory you're symlinking from will need to be accessible by the jenkins user. And it likely violates a lot of best practices.