I notice that the httpclient instantiated in the UploadFiles class is saved in a transient field (because is not serialisable) to be closed later in the build step.
The UploadFiles is a MasterToSlaveFileCallable and by design it could be executed on a slave node. The httpclient instantiated in the UploadFiles.invoke() method could not be closed because the httpclient instance is not serialised back to the master node.
To ensure the httpclient is closed correctly I moved the instantiation of the HTTP client inside the specific Uploader implementations, this has two advantages:
Uploader can handle the whole HTTP client lifecycle during the execution in a Jenkins node and close when the task is completed;
customise the client configuration for each Uploader implementation (for example in case new version use different authentication methods or use XML instead JSON etc etc)
I notice that the httpclient instantiated in the UploadFiles class is saved in a transient field (because is not serialisable) to be closed later in the build step.
The UploadFiles is a
MasterToSlaveFileCallable
and by design it could be executed on a slave node. The httpclient instantiated in theUploadFiles.invoke()
method could not be closed because the httpclient instance is not serialised back to the master node.To ensure the httpclient is closed correctly I moved the instantiation of the HTTP client inside the specific Uploader implementations, this has two advantages: