Invalidate cache of Nexus group repository via Groovy

Hello Community,

Is there any preferred method to invalidate cache via a Groovy script which can be executed by Nexus task executor?

Following the groovy scripting guide provided at (GitHub - sonatype-nexus-community/nexus-scripting-examples: Sample scripts that use NXRM's scripting interface).

I think the Repository API for scripts (REST and Integration API) only allows to view the content/create new repositories via Groovy. Could this API be somehow extended to invalidate group repository cache via Groovy?

Would manually creating an Object of RepositoryCacheInvalidationService class in Groovy (nexus-public/RepositoryCacheInvalidationService.java at main · sonatype/nexus-public · GitHub) to call cache invalidation function work? Or could there be a better way to handle it via Groovy?

As of now I could only found a way to do it via a cURL POST request <nexus-url/service/rest/v1/repositories/npm-group/invalidate-cache> .

Many thanks in advance for your support.

Cheers

I tried this approach but getting 204 respo?Is it correct?..or it should give 200

There is a REST API you can use check the API section of the Admininstrator UI under Repository Management

If you’re using PowerShell (Not Windows PowerShell), this command is what you want, obviously change the repo name and the server name/ port number

Invoke-RestMethod -Uri https://SERVER:PORTNUMBER/service/rest/v1/repositories/REPOSITORYNAME/invalidate-cache -Method POST -ContentType 'application/json' -Authentication Basic -Credential (Get-Credential)