Search code examples
groovynexusnexus3

How can I associate an Routing Rule to a proxy repository on Nexus OSS via Groovy?


I’ve been able to create, using the Nexus groovy scripts, more specifically associating a Routing Rule to and existing repository.

It’s pretty easy to create one; such code evaluated fine from Groovy: RoutingRule routingRule = new RoutingRule("com.company only API", "only com.company content", RoutingMode.BLOCK, ["^(?!/com/company)/.*\$"])

The part I could not figure out was how to persist this rule and attach it to an existing repository. I tried with: Configuration.setRoutingRuleId(EntityHelper.id(ruleName)) without success.

Anyone know-how is the correct configuration to associate a proxy repository to a routing rule?

Nexus OSS version: 3.19.1-01

Edit: I solved my problem by updating my version of Nexus to OSS 3.21.1-01 and start using the API that now they have RoutingRules methods.


Solution

  • Not sure if you've found an answer here given it's already 2 months old. I was also having this problem and took me long to figure this out so for anyone looking:

    def rule = routingRuleStore.getByName('RULENAME')
    config.routingRuleId = org.sonatype.nexus.common.entity.EntityHelper.id(rule)
    

    Then you can save/update with

    repositoryManager.create(config)
    repositoryManager.update(config)