Skip to content
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

Workflow onComplete/onError handlers don't work when defined in the entry workflow #5261

Open
bentsherman opened this issue Aug 27, 2024 · 1 comment · May be fixed by #5366
Open

Workflow onComplete/onError handlers don't work when defined in the entry workflow #5261

bentsherman opened this issue Aug 27, 2024 · 1 comment · May be fixed by #5366
Labels
Milestone

Comments

@bentsherman
Copy link
Member

The following example:

workflow {
    params.outdir = 'results'

    workflow.onComplete {
        if( workflow.success )
            log.info "Success! View results: $params.outdir"
        else
            log.info "Failure!"
    }
}

Fails with an error that workflow is null in the onComplete handler, even though it should be in scope. The same error will happen for params if it is accessed first. These handlers should work regardless of whether they are defined at the script level or in the entry workflow.

There are two workarounds:

  1. Assign the onComplete handler: workflow.onComplete = { ...
  2. Declare local variables that reference workflow and params:
    def myParams = params
    def myWorkflow = workflow
    workflow.onComplete {
      // ...
    }
@PikalaxALT
Copy link

Documentation recommends the failing case, so either the issue should be fixed or the documentation should be amended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants