Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should I use Jenkins heavyweight or flyweight executors for notifications?

I have few steps in my Jenkins pipeline that notify users, in my case using Slack integration.

is it a good practice to write the notification code inside a node block to use a heavyweight executor or just leave it outside to make use of a flyweight executor?

According to the documentation:

Every Pipeline build itself runs on the master, using a flyweight executor — an uncounted slot that is assumed to not take any significant computational power.

This executor represents the actual Groovy script, which is almost always idle, waiting for a step to complete.

Flyweight executors are always available.

After reading this, it is still not clear to me if it is considered a good practice for notifications to use a heavyweight or flyweight executors

like image 455
yeforriak Avatar asked Mar 08 '23 19:03

yeforriak


2 Answers

Most steps will let you know that they require a (heavyweight) executor slot (node/agent) - see Daniels answer.

Remember, executors (heavyweight) are Jenkins way to prevent an overload on the machine Jenkins is running on. By limiting the number of executors you're limiting the number of tasks Jenkins is executing in parallel and therefore the required resources.

For notifications it should be fine to use a lightweight executor (if it works without a node) as it doesn't need much resources of your jenkins machine. It still depends on your use case how much it really matters if notifications are executed with a regular or a lightweight excecutor. If it only takes some milliseconds/ a second to send this notification and if you have (in average) enough free executors, it doesn't hurt to use a node aka executor. Then it is often easier to use one node / agent for your complete pipeline.

On the other hand make sure that you're pipeline doesn't block an executor forever. E.g. if you use an input step and the pipeline therefore waits long time on user input. Here the usage of the lightweight executor is important. Also timeout configuration for networks request and other potentially long running task are helpful to prevent blocked (regular) executors.

Hope this helps to give you some more direction.

like image 64
Philip Avatar answered Apr 24 '23 09:04

Philip


I tried the flyweight executor but got the following error when sending emails:

Required context class hudson.FilePath is missing

To avoid these kind of problems, I would choose the heavyweight executor.

like image 37
Daniel Steinmann Avatar answered Apr 24 '23 09:04

Daniel Steinmann