Jenkins Pipelines – Understanding Flyweight and Heavyweight Executors

Jenkins have two type of executors – flyweight and heavyweight.

Flyweight executor is actually a Java thread that is running on Jenkins Master node. Jenkins automatically create Flyweight executors when needed and their number is unlimited.

Heavyweight executors are running on Jenkins Slave nodes and their number can be configured on node’s configuration.

Every Pipeline Groovy script runs on the Master node using a flyweight executor, in other words in separate Java thread. But sh and bat scripts will be executed on a heavyweight executor when inside node block.
Therefore heavy logic should run only on those steps.

So in order to reduce the resource usage of flyweight executors you should use shell script steps for any pipeline logic that requires significant machine resources. For example instead of directly calling Groovy library in your Pipeline, you should move that logic into standalone script and execute it via shell step that calls Groovy from command line.

This technique improves stability of your Jenkins Master node and makes the Pipeline specific parts easier to debug and test.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.