Write Plugins
Note
JFrog Workers is the newer, recommended way to easily extend the JFrog Platform (not just Artifactory) in a Cloud-native way. While plugins are supported, we strongly suggest using JFrog Workers whenever possible.
Artifactory plugins are written as Groovy scripts in regular files and have a simple DSL to wrap users code in closures inside well-known extension points.
Scripts have a couple of helper objects that are globally bound (see the plugin script template).
Naming conventions
Note that Groovy scripts must follow the same naming conventions as those specified for Java.
The Artifactory Public API (PAPI)
Scripts have access to the full classpath of Artifactory. However, the only API supported for plugins is the Artifactory Public API, defined in artifactory-papi.jar.
You can find the artifactory-papi.jar under WEB-INF/lib folder inside artifactory.war.
For more information, see Plugin Code Template.
IDE code completion
All major IDEs have good Groovy editing and debugging capabilities.
In order to make your developing experience complete, we provide support for our own DSL for IntelliJ IDEA. IntelliJ IDEA's Groovy DSL script for Artifactory User Plugins can be found in our GitHub repo.
Eclipse DSLD file is also available courtesy of James Carnegie.
Globally Bound Variables
Closure Variables
Note! Declaring your own closure variables using the Groovy 'def ' keyword is considered best practice. Avoiding the "def" keyword is risky in terms of variable scoping, and will result in the variable being scoped globally, making it accessible from other closure executions.
Plugins Repository
Enhancing Artifactory with user plugins is community-driven effort.
If you are looking to go beyond Artifactory's out-of-the-box functionality take a look at already contributed plugins on GitHub, you might find what you are thinking about. If not, your contribution is very welcome!
Plugin Execution Points
The following table summarizes the available execution points. For more details about specific plugins, follow the section links.
User Plugin Execution Context
The Download, Storage, Execution ,and Build plugin types are executed under the identity of the user request that triggered them.
It is possible to force a block of plugin code to execute under the "system" role, which is not bound to any authorization rules and can therefore perform actions that are otherwise forbidden for the original user.
To run under the "system" role wrap your code with the asSystem closure:
... someCode ...
asSystem {
//This code runs as the system role
}
... someOtherCode ...
Including AQL Queries
User plugins may include AQL queries opening up the full set of search capabilities that AQL has to offer. AQL queries are implemented within the Searches object as shown in the example below.
import org.artifactory.repo.RepoPathFactory
import org.artifactory.search.Searches
import org.artifactory.search.aql.AqlResult
executions {
gemPropsPopulator() {
def repoKey = "gem-local"
((Searches) searches).aql(
"items.find({" +
"\"repo\": \"" + repoKey + "\"," +
"\"\$or\":[" +
"{\"property.key\":{\"\$ne\":\"gem.name\"}}," +
"{\"property.key\":{\"\$ne\":\"gem.version\"}}" +
"]})" +
".include(\"path\", \"name\")") {
AqlResult result ->
result.each {
...
...
...
}
}
}
}Updated 3 months ago

