Workflow introspection
Runtime metadata
The implicit workflow object allows you to access some workflow and runtime metadata in your Nextflow scripts. For example:
println "Project : $workflow.projectDir"
println "Git info: $workflow.repository - $workflow.revision [$workflow.commitId]"
println "Cmd line: $workflow.commandLine"
println "Manifest's pipeline version: $workflow.manifest.version"
Tip
To shortcut access to multiple workflow properties, you can use the Groovy with method.
The following table lists the properties that can be accessed on the workflow object:
workflow.commandLineCommand line as entered by the user to launch the workflow execution.
workflow.commitIdGit commit ID of the executed workflow repository.
When providing a Git tag, branch name, or commit hash using the
-rCLI option, the associatedworkflow.commitIdis also populated.workflow.completeAvailable only in the
workflow.onCompletehandlerTimestamp of workflow when execution is completed.
workflow.configFilesConfiguration files used for the workflow execution.
workflow.containerDocker image used to run workflow tasks. When more than one image is used it returns a map object containing
[process name, image name]pair entries.workflow.containerEngineReturns the name of the container engine (e.g. docker or singularity) or null if no container engine is enabled.
workflow.durationAvailable only in the
workflow.onCompletehandlerTime elapsed to complete workflow execution.
workflow.errorMessageAvailable only in the
workflow.onCompleteandworkflow.onErrorhandlersError message of the task that caused the workflow execution to fail.
workflow.errorReportAvailable only in the
workflow.onCompleteandworkflow.onErrorhandlersDetailed error of the task that caused the workflow execution to fail.
workflow.exitStatusAvailable only in the
workflow.onCompleteandworkflow.onErrorhandlersExit status of the task that caused the workflow execution to fail.
workflow.failOnIgnoreNew in version 24.05.0-edge.
Whether the
workflow.failOnIgnoreconfig option was enabled.See errorStrategy for use-cases of this option.
workflow.fusion.enabledWhether Fusion is enabled.
workflow.fusion.versionFusion version in use.
workflow.homeDirUser system home directory.
workflow.launchDirDirectory where the workflow execution has been launched.
workflow.manifestEntries of the workflow manifest.
workflow.previewNew in version 24.04.0.
Returns
truewhenever the current instance is a preview execution.workflow.profileUsed configuration profile.
workflow.projectDirDirectory where the workflow project is stored in the computer.
workflow.repositoryProject repository Git remote URL.
workflow.resumeReturns
truewhenever the current instance is resumed from a previous execution.workflow.revisionGit branch/tag of the executed workflow repository.
When providing a Git tag or branch name using the
-rCLI option, theworkflow.revisionis also populated.workflow.runNameMnemonic name assigned to this execution instance.
workflow.scriptFileProject main script file path.
workflow.scriptIdProject main script unique hash ID.
workflow.scriptNameProject main script file name.
workflow.sessionIdUnique identifier (UUID) associated to current execution.
workflow.startTimestamp of workflow at execution start.
workflow.stubRunReturns
truewhenever the current instance is a stub-run execution .workflow.successAvailable only in the
workflow.onCompleteandworkflow.onErrorhandlersReports if the execution completed successfully.
workflow.userNameUser system account name.
workflow.wave.enabledWhether Wave is enabled.
workflow.workDirWorkflow working directory.
Nextflow metadata
The implicit nextflow object allows you to access the metadata information of the Nextflow runtime.
nextflow.buildNextflow runtime build number.
nextflow.timestampNextflow runtime compile timestamp.
nextflow.versionNextflow runtime version number.
nextflow.version.matches()Check whether the Nextflow runtime satisfies a version requirement.
The version requirement string can be prefixed with the usual comparison operators:
=or==: equal to<(<=): less than (or equal to)>(>=): greater than (or equal to)!=or<>: not equal
For example:
if( !nextflow.version.matches('>=23.10') ) { error "This workflow requires Nextflow version 23.10 or greater -- You are running version $nextflow.version" }
Alternatively, the version can be postfixed with
+, which is similar to==but also allows the last version part to be greater. For example,23.10.1+is satisfied by23.10.1and23.10.2, but not23.11.xor23.09.x. Additionally,23.10.+is equivalent to23.10.0+. This operator is a useful way to enforce a specific version while allowing for newer patch releases.
Completion handler
Due to the asynchronous nature of Nextflow the termination of a script does not correspond to the termination of the running workflow. Thus some information, only available on execution completion, needs to be accessed by using an asynchronous handler.
The onComplete event handler is invoked by the framework when the workflow execution is completed. It allows one to access the workflow termination status and other useful information. For example:
workflow.onComplete {
println "Pipeline completed at: $workflow.complete"
println "Execution status: ${ workflow.success ? 'OK' : 'failed' }"
}
If you want an e-mail notification on completion, check Mail & Notifications.
Error handler
The onError event handler is invoked by Nextflow when a runtime or process error caused the pipeline execution to stop. For example:
workflow.onError {
println "Error: Pipeline execution stopped with the following message: ${workflow.errorMessage}"
}
Note
Both the onError and onComplete handlers are invoked when an error condition is encountered. The first is called as soon as the error is raised, while the second is called just before the pipeline execution is about to terminate. When using the finish errorStrategy, there may be a significant gap between the two, depending on the time required to complete any pending job.
Decoupling metadata
The workflow event handlers can be defined also in the nextflow.config file. This is useful to decouple the handling of pipeline events from the main script logic.
When the event handlers are included in a configuration file the only difference is that the onComplete and the onError closures have to be defined by using the assignment operator as shown below:
workflow.onComplete = {
// any workflow property can be used here
println "Pipeline complete"
println "Command line: $workflow.commandLine"
}
workflow.onError = {
println "Error: something when wrong"
}
Note
It is possible to define workflow event handlers both in the pipeline script and in the configuration file.