Extended Jenkins parallel abilities

Hi again! I have new interesting task that is not handled by Jenkins functionality.
I have pipeline that interacts with some devices. During interaction I want to capture devices serial output and publish it as Jenkins artifact.
Parallel step will not help me in this case, because:

  1. Telnet connection will be alive until I will not stop it. So parallel branch will be executing forever
  2. Parallel step will freezes pipeline execution until all branches are completed

I’m thinking about custom threading implementation in shared library using workflow-api plugin or write own plugin that will extend parallel functionality. For example:

  1. Releasing threads (should be stopped anyway on build finish.
  2. Ability to monitor thread state in runtime (Manipulating Future<> to obtain information about thread status/results).

What is “Jenkins way” for such cases? Had somebody experience with such tasks and how you solved it? May be there is some plugin that will help me?

UPD:
I made some research to understand what is happening.
CpsThreadGroup is an analog of thread pool from Java threading and CpsThread is analog of generic thread from Java threading. Flow node is a task which should be executed by thread. Each CpsThread takes Flow Nodes one by one and executes it. If parallel step called, for each branch CPS thread is created and Flow nodes for each branch are execution bodies (closures) of parallel branches. So in my case I need to inherit CpsThreadGroup or CpsThread, customize execution logic, and invoke them as in parallel step source code?
Am I right in my suggestions?

1 Like

Some updates. Unfortunately it is not possible to customize threading from shared library because it required StepContext. So I’ve tried to create plugin which will add custom parallel step with ability to release threads.
I failed due to blocker in design of CpsBodyInvocation here: https://github.com/jenkinsci/workflow-cps-plugin/blob/3e8bc1c5f9eaedb7166d71b7ba173ef6cbe119ca/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsBodyInvoker.java#L140
Comments related to addedSynchrously boolean variable and further conditions says that in async mode the first parallel branch will be executed in the same thread as pipeline. For other branches separate CPS threads will be created. If step is synchronous, all branches will be invocated in the same thread as pipeline.
This means that it does not matter in which mode step would be executed. Anyway thread which executes pipeline will have minimum 1 branch to execute. So parallel can not be “released” by design.
Does anyone have ideas what I can try?) May be I can ask somebody from Jenkins developers to pay attention to this?