Docker Agent template usage in CJE

Issue

When jobs are built on an agent built from a Docker Agent template, it can happen that the workspace is not empty.
Why is the container not new?

Environment

Resolution

The current implementation of the Docker Agent template instances rely on the Cloud endpoint in Jenkins.
This endpoint can re-use an agent, if before the agent got destroyed, a new build requests an agent with the same label.
This is to prevent creating a new agent each time when an existing one could be used.

This means that when you are using such an agent, you need to validate its state when you receive it:

  • empty the workspace with deleteDir() step
  • unstash or checkout required files for the stage.

You should not rely on the assumption that files are present or absent.
If you try to unstash a file which might be in the workspace, you will face an exception.
You should always start your stage with deleteDir() step.
The current implementation of the Docker Agent template instances rely on the Cloud endpoint in Jenkins.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.