Groovy plugin for Artifactory to restrict move from one Repo to particular repo

StackOverflow https://stackoverflow.com/questions/20963882

  •  25-09-2022
  •  | 
  •  

سؤال

I have 3 repo's in my Artifactory and want to handle the movement of Artifacts through plugin.

1. Build-repo
2. Testing-repo
3. Prod-repo

Trying to create a plugin to allow Move of Artifact from one Repo (Build-repo) to other repo (Testing-repo) only. I should stop developers to move directly from Build-repo to Prod-repo

Similarly Testing-repo -> Prod-repo

 beforeMove { item, targetRepoPath, properties ->
        log.debug("ENTER storage -> beforeMove")
        if (!security.isAdmin() && item.repoKey.equals("Build-repo")) {
        if (item.targetRepoKey.equals("Prod-repo")) {
                    throw new CancelException("Artifact Move not permitted for ${item.repoKey}: ", 403)
            }
    }
        log.debug("EXIT storage -> beforeMove")

But I get a error, This could just be a issue with the usage of Property. How do I get the complete list of Properties for using groovy plugin.

Caused by: groovy.lang.MissingPropertyException: No such property: targetRepoKey for class: org.artifactory.model.xstream.fs.FileInfoImpl
هل كانت مفيدة؟

المحلول

The property the error refers to is not Artifactory property, but Groovy object property. In line 4 you have item.targetRepoKey, while it should be item.repoKey.

I strongly recommend you using a proper IDE (IntelliJ IDEA) and using trypes in your code e.g. line 1 should be:

beforeMove { FileInfo item, RepoPath taretRepoPath, Properties properties ->

That can save you time struggling with such errors.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top