
tshavetheyak.jenkins-std-lib.0.1.1.source-code.bash.txt Maven / Gradle / Ivy
Run your script with Bash!
All bash commands use formatBash() to first format your script.
Examples:
-
Running a script and printing the output (stdout + stderr).
-
def result = bash('echo "hey"')
println("Result output is: ${result}")
hey
Result output is: hey
-
Running a script but not outputing to the console.
-
def result = bash.silent('echo "hey"')
println("Result output is: ${result}")
Result output is: hey
-
Using the result object.
-
def result = bash.silent('echo "hey"')
println("output is: ${result.output}")
println("stderr is: ${result.stdErr}")
println("stdout is: ${result.stdOut}")
println("exitcode is: ${result.exitCode}")
output is: hey
stderr is:
stdout is: hey
exitcode is: 0
-
Handling errors.
-
try{
result = bash.silent('fakecommand')
}catch(ScriptError ex){
print(ex)
}
org.dsty.exceptions.ScriptError: Script exitCode was 127 and stderr:
/var/jenkins_home/workspace/shared-lib@tmp/durable-1ddd6acb/script.sh: line 6: fakecommand: command not found
ScriptError Exception has the same fields as the result object.
-
Ignoring errors.
-
def result = bash.ignoreErrors('fakecommand', consoleOutput=false)
print(result.stdErr)
/var/jenkins_home/workspace/shared-lib@tmp/durable-47d162ed/script.sh: line 6: fakecommand: command not found
Avaliable methods:
-
Result call(String userScript)
-
Runs a bash script that sends all output to the console and returns a result object.
-
Result silent(String userScript)
-
Runs a bash script that sends no output to the console and returns a result object.
-
Result ignoreErrors(String userScript, Boolean consoleOutput=true, Boolean failFast=false)
-
Runs a bash script that ignores errors. failFast controls if script should stop on first error or not.
-
String formatScript(String userScript, Boolean consoleOutput=true, Boolean failFast=true)
-
Formats a bash script by adding the shebang, setting the verbose level and sourcing bashrc.