User Plugins

Skip to end of metadata
Go to start of metadata
Table of Contents

About Plugins

Artifactory Pro allows you to easily extend Artifactory's behavior with your own plugins written in Groovy.

User plugins are about running user's code in Artifactory. Plugins allow you to do things like:

  • Adding scheduled tasks
  • Extend Artifactory with your own security realms
  • Change resolution rules
  • Manipulate downloaded content
  • Respond to any storage events
  • Deploy and query artifacts and metadata
  • Perform searches
  • Query security information
  • Invoke custom commands via REST
  • Execute custom promotion logic
  • Provide information and strategies for Artifactory's build servers plugins.

During development you can change plugin source files and have your plugins redeployed on the fly. You can even debug the plugin code using your favorite IDE.

Deploying Plugins

Simple place your plugin files under ${ARTIFACTORY_HOME}/etc/plugins.
Any file name ending with .groovy will be loaded on startup. You can have multiple plugin files which will be loaded in alphabetical order. Callbacks defined in plugins will be called by the order plugins were loaded.

Auto Reload

By default plugins are not reloaded after Artifactory has started up. You can tell Artifactory to automatically detect plugin changes on disk or new plugin files and automatically reload them in runtime (plugin removals are not detected). To do this, set the number of seconds to check for plugin updates to a number greater than 0, by changing the following property in ${ARTIFACTORY_HOME}/etc/artifactory.system.properties, or by specifying the property with -D to the JVM running Artifactory:

Production use

Do not leave the plugins auto-reload feature active in a production environment.

Writing Plugins

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.

A scripts have a couple of helper objects that are globally bound (see the plugin script template).

The Artifactory Public API (PAPI)

Scripts have access to the full classpath of Artifactory, however, the only API supported for plugins is the (info) Artifactory Public API, defined in the artifactory-papi.jar.
The artifactory-papi.jar can be found under WEB-INF/lib folder inside the artifactory.war.

Please see the plugin code template and sample plugin below for more details.

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.

  • Please note that the script is a work in progress. Currently only globally bound variables are supported. We are working on adding plugin-specific variables.

Globally Bound Variables 

Variable NameVariable TypeComments
log
org.slf4j.Logger
Writes to Artifactory log
logger name is the name of the script file 
repositories
org.artifactory.repo.Repositories
Allows queries and operations on repositories
and artifacts 
security
org.artifactory.security.Security
Provides information about current security context,
(e.g. current user and her permissions) 
searches
org.artifactory.search.Searches
API for searching for artifacts and builds
Since 2.3.4 
builds
org.artifactory.build.Builds

Allows CRUD operations on builds
Since 2.6

Plugins Repository

Enhancing Artifactory with user plugins is community-driven effort. If you are looking for going beyond Artifactory's out-of-the-box functionality take a look at already contributed plugins on GitHub, maybe you'll 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 plugin look follow the section links.

Plugin Type

Code block name

When executed

Description

Download
Event Callback (with return values)
 
 
altResponse

On any download

Provide an alternative response, by setting a success/error status code value and an optional error message or by setting new values for the inputStream and size context variables (For succeeded resolutions).

altRemotePath

When reaching out to remote repositories

Provides an alternative download path under the same remote repository, by setting a new value to the path variable.

altRemoteContent

After fetching content from remote repositories

Provide an alternative download content, by setting new values for the inputStream and size context variables.
afterDownloadError
After failing during content fetching from remote repositoriesProvide an alternative response, by setting a success/error status code value and an optional error message or by setting new values for the inputStream and size context variables (For failed resolutions).

Event Callback (without return value)

 
 
beforeRemoteDownload
Before fetching content from remote repositoriesHandle before remote download events.
afterRemoteDownload 
After fetching content from remote repositoriesHandle after remote download events.
beforeDownload
On any downloadHandle before download events.
Storage
Event Callback (without return value)
before/after
Create, Delete, Move, Copy
Before / After selected storage operationHandle events before and after Create, Delete, Move and Copy operations
Jobs
Scheduled executionany valid Groovy (Java) literal as execution nameAccording to provided interval/delay or CRON expression

Job runs are controlled by the provided interval or cron expression, which are mutually exclusive. The actual code to run as part of the job should be part of the job's closure.

Executions
User-driven executionany valid Groovy (Java) literal as execution nameBy REST callExternal executions are invoked via REST POST requests.
Realms
Event Callback (without return value)

any valid Groovy (Java) literal as realm name with nested blocks:

authenticate
userExists
During user authenticationNewly added realms are added before any built-in realms (Artifactory internal realm, LDAP, Crowd etc.). User authentication will be attempted against these realms first, by the order they are defined.
Build
Event Callback (without return value)
beforeSave 
Before the build info is saved in ArtifactoryHandle before build info save events
afterSave 
After the build info is saved in ArtifactoryHandle after build info save events
Promotions
User-driven executionany valid Groovy (Java) literal as promotion nameBy REST callPromotes integration (a.k.a. snapshot) build to be a release invoking any code associated with it.

Plugin Template Source

General Info

 

Download

A section for handling and manipulating download events
 

 

Storage

A section for handling and manipulating storage events

If you wish to abort an action you can do that in 'before' methods by throwing a runtime org.artifactory.exception.CancelException with an error message and a proper http error code.

 

Jobs

A section for defining scheduled jobs
 

 

Executions

A section for defining external executions

Since: 2.3.1 - External executions are invoked via REST POST requests. For example:

curl -X POST -v -u admin:password "http://localhost:8080/artifactory/api/plugins/execute/multiply?params=msg=And+the+result+is:|no1=10|no2=15&async=0"

 

Realms

A section for management of security realms

Realms defined here are added before any built-in realms (Artifactory internal realm, LDAP, Crowd etc.). User authentication will be attempted against these realms first, by the order they are defined.

 

Build

A section for handling build info events

Since 2.6

 

Promotions

A section for defining REST executable build promotion operations

Since 2.6

 

Sample Plugin

Labels: