Issue
A common way for clients that desire a clean build agent workspace for every build would be to utilize an ephemeral agent architecture, for example using Kubernetes plugin.
If you have specialized hardware that is required for your build, and not enough of that hardware to dedicate to each controller in your cluster, you likely will want to utilize Shared agents. However, you may still want to have a clean workspace for each build.
Resolution
There are two solutions to this problem:
-
Have developers to update their
Jenkinsfile
to add the deleteDir() step at the start of the Pipeline. -
Update the shared agent configuration to delete the workspace each time the agent is leased:
-
Under the
Launch method
chooseLaunch build agents via SSH (Non-blocking I/O)
-
Under the
Advanced
section, underPrefix Start Agent Command
add the command:rm -rf /home/agent/*/workspace/ &&
(note to modify/home/agent
to be the path you chose for theRemote FS root
)
-
This /home/agent/*/workspace/ has a * in it, since for shared agents, each controller will get a random ID directory under the Remote FS root and the workspace is a subdirectory below that directory (if it was a permanent agent directly connected to a controller, the command would be rm -rf /home/agent/workspace/ && )
|