Hi together. I have worked on this issue and now you can use it inside of a pipeline. Have a look at my fork at https://github.com/m00re/port-allocator-plugin
Usage:
wrap([$class: 'PortAllocator', pool: 'POOLNAME']) {
}
So far, I only added support for Pooled Ports (from within the pipeline), but the required changes to support other port types should be marginal. The changes also make sure that you can mix between classic job descriptions and pipeline projects.
What is not yet working: surviving Jenkins restarts. For us/me, this is not a requirement, but I am willing to add support for this too if someone provides me the necessary pointers (I already tried, but as this was my first Jenkins plugin work, my knowledge of Jenkins plugin interna is very limited).
PortAllocator would need to become a SimpleBuildWrapper. There are various places AbstractBuild would need to be replaced by Run, and similar minor changes. To survive Jenkins restarts, that means Port must become Serializable, cleanUp needs to be passed in sufficient context that Port need not keep unserializable state, and PortAllocationManager needs to become a persistent Extension (using load/save) with ports keeping only Run.externalizableId and INSTANCES being keyed by Node.name. Pool probably also needs to be come Serializable, enabling PooledPortType to work, and then other types like TomcatShutdownPortType needs to be modified to use static Serializable nested classes for cleanup work. Overall a fairly major refactoring, akin to what I had to do for
JENKINS-26477.