Reputation: 5656
I have some large bash scripts in my job dsl files that I am declaring as
String script = '''
# large script
'''
and calling it from the shell
method
shell(script)
How ever, I would like to break out the scripts into shell files. I tried declaring
String script = new File('script.sh').text
But the job that executes the jenkins job dsl script does not appear to find the file, in fact I am not sure which location it is even executing from.
Upvotes: 1
Views: 523
Reputation: 7982
Use readFileFromWorkspace to read the contents of a file from a job workspace.
The path is specified relative to the workspace root.
The second example on the linked API docs above is for a batch file, but replace batch with shell and you have the solution for your case.
def runScript = readFileFromWorkspace('script.sh')
job('example-2') {
steps {
shell(runScript)
}
}
Upvotes: 1