This plugin enables users to perform different administrative, maintenance, setup (pre-build), or cleanup (post-build) tasks on a specific agent each time a build is executed.
It functions differently from several similar plugins that typically allow users to define tasks These plugin usually define these tasks as build-steps, therefore ties them only to a specific job. These tasks are then run everytime a build of this job is executed, regardless of the agent which executes it.
Adaptive Jenkins Agent plugin takes an opposite approach by allowing users to specify tasks to be run on a particular agent everytime it executes a build, regardless of what build is being executed.
To accomplish this, the plugin allows users to define various tasks that should be executed on the agent before, during, or after any build. Users can also set conditions for these tasks, ensuring that they are only performed on the agent if the specified conditions are met.
User can configure it in the node properties section of agent's configuration page:
The plugin also defines extension points for defining additional conditions and tasks.
There are 3 extensions points for adding new tasks:
- PreBuildAction - task which can be selected to run before a build
- PostBuildAction - task which can be selected to run after a build
- DuringBuildAction - task which can be selected to run during a build
Classes implementing any task interface have to implement a method runAction() which runs the logic of an task.
There are 3 extensions points for adding new conditions:
- PreBuildCondition - condition which can be selected for actions run before a build
- PostBuildCondition - condition which can be selected for actions run after a build
- DuringBuildCondition - condition which can be selected for actions run during a build
Classes implementing any condition interface have to implement method conditionPasses() which returns a boolean whether the condition passes.
User can select 3 categories of tasks:
- Run after a build
- Run before a build
- Run during a build - this requires user to specify a period in which it loops
Below is an example how to configure a task, whose condition is evaluated every 2 seconds, and stops once the condition evaluates (and task is executed)
This plugin also adds few basic tasks which user can select:
Removes build's workspace
Reboots agent's system
Takes agent offline so no more new build are acceptedea nad waits for all the build running on the agent to finish before rebooting
Conditions which can be combined with above-mentioned tasks. Tasks are only run of condition passes:
Task is run only if available disk space or bigger/lesser than specified value
Task is run only if duration of a build is bigger/lesser than specified value
Task if average duration of N past builds is bigger/lesser than specified value
Task is run only N past builds have failed
Task is run everytime
Task is run of build executed by the agent has some specific result
Task is run only if script returns zero value