-
Notifications
You must be signed in to change notification settings - Fork 198
[JENKINS-54514] Document error handling in the 'parallel' step #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,69 @@ | ||
| <div> | ||
| <p> | ||
| Takes a map from branch names to closures and an optional argument <code>failFast</code> | ||
| which will terminate all branches upon a failure in any other branch: | ||
| </p> | ||
| <pre> | ||
| parallel firstBranch: { | ||
| // do something | ||
| }, secondBranch: { | ||
| // do something else | ||
| }, | ||
| failFast: true|false | ||
| </pre> | ||
| Takes a map from branch names to closures and runs the closures in | ||
| parallel. The optional <code>failFast</code> option terminates | ||
| all jobs as soon as any job fails. | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </p> | ||
| <p> | ||
| Synopsis: | ||
| <pre> | ||
| parallel firstBranch: { | ||
| // do something | ||
| }, secondBranch: { | ||
| // do something else | ||
| }, | ||
| failFast: true|false | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </pre> | ||
| </p> | ||
| <p> | ||
| A branch succeeds if it returns normally. The actual value | ||
| returned does not matter. A branch is considered to have failed if its | ||
| closure exits by throwing an exception. | ||
| </p> | ||
| <p> | ||
| If any branch fails, the <code>parallel</code> step will throw that | ||
| exception once all branches have finished executing or been terminated, | ||
| depending on <code>failFast</code> mode. Any non-identical exceptions | ||
| thrown by other branches are added to the first exception as having been | ||
| "suppressed by" the first exception; see | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <code>Throwable.addSuppresssed(...)</code>. | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </p> | ||
| <p> | ||
| Note that a <code>hudson.AbortException</code>, as thrown by failing | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think mentioning |
||
| steps, will stop and fail the branch but not produce a stack trace. | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| This produces a: | ||
| <pre> | ||
| [branchname] Failed in branch branchname | ||
| </pre> | ||
| message without any details. | ||
| </p> | ||
| <p> | ||
| To report results from branches to the outer script, use the closure's | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| access to the outer scope's variables. For example, to run a shell script | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| in parallel on each of a list of arguments and produce a map of argument | ||
| to script stdout: | ||
| <pre> | ||
| def args = ['foo', 'bar', 'baz'] | ||
| def results = [:] | ||
| // Produce a map of args to closures that use each arg | ||
| branches = args.collectEntries { arg -> [(arg): { | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def out = sh script: "./my-script.sh '${arg}'", returnStdout: true | ||
| results << [(arg): out] | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return null | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } ] } | ||
| branches << [failFast: true] | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| parallel branches | ||
| </pre> | ||
| If all the scripts returned 0, the 'results' array contains a map of arg | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| to shell stdout string. Otherwise <code>parallel</code> terminates the | ||
| other branches and re-throws the <code>hudson.AbortException</code> from | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| the first failed script. | ||
| </p> | ||
| <p> | ||
| Note: Branch closures should just return <code>null</code>. The return | ||
|
||
| value of the <code>parallel</code> step should be ignored. | ||
| <code>parallel</code> does capture the return values of closures and | ||
| return a map of branch name to return value. But relying on this is not | ||
| recommended and the behaviour is subject to change; See JENKINS-26033. | ||
bitwiseman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </p> | ||
| </div> | ||
Uh oh!
There was an error while loading. Please reload this page.