I have a setup with a main Jenkins server and two static VMs configured as agents. One VM runs Ubuntu with Docker installed. The other static VM runs Windows 10 so that I can run tests on Windows.
The following pipeline hangs on the bat step in the 2nd stage. I've let it run overnight with no progress.
def staticVMWithDockerLabel = // label for the Ubuntu static agent with Docker def staticVMWindowsLabel = // label for the Windows static agent. pipeline { agent { docker { label staticVMWithDockerLabel image 'ubuntu:20.04' alwaysPull true } } stages { stage('Main Agent') { steps { echo 'On main agent' sh 'echo script ran on main agent' echo 'End main agent' } } stage('Windows Agent') { agent { label staticVMWindowsLabel } steps { echo 'On Windows agent' bat 'echo script ran on Windows agent' echo 'End Windows agent' } } stage('Main Agent Again') { steps { echo 'On main agent again' sh 'echo script ran on main agent again' echo 'End main agent again' } } } }
When this pipeline runs:
- The Docker instance is started as expected.
- The first stage, 'Main Agent' runs successfully within the Docker instance. The console includes the expected text.
- The second stage starts successfully. But then it hangs on the bat step. The console output ends with:
[Pipeline] stage
[Pipeline] { (Other Agent)
[Pipeline] node
Running on <agent name> in <workspace>
[Pipeline] {
[Pipeline] echo
On Windows agent
[Pipeline] bat
No additional content in console output
Alternatives:
- If using dockerfile instead of docker the same hang occurs. This is my actual use case; using docker in the above example makes it easier to reproduce.
- If I stop using Docker and instead use the static VM agent directly (i.e., If I replace the pipeline level agent with "agent { label staticVMWithDockerLabel }") then everything works as expected. However, I lose the ability to control agent configuration per project that Jenkins' Docker integration gives me.
- If I change the pipeline level to "agent none" and put the Docker agent on stages 1 & 3, it works. However, I lose the ability for stages 1 & 3 to run in the same container instance.