Build retention can be configured using the REST API. The endpoint for this is:Control Build Retention - [REST API]