Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60119

Declarative pipeline with Docker image not running steps inside container on Windows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: docker-workflow-plugin
    • Labels:
      None
    • Environment:
      Windows Server 2019 (1809) agent node running Docker 19.03.4, Docker Pipeline 1.21
    • Similar Issues:

      Description

      I'm running a very simple test with a Nano Server container, now that the Docker Pipeline plugin has Windows support, but the steps in my stage appear to be running on the agent node instead. The pipeline looks like this:

      pipeline {
        agent {
          docker { 
            image 'mcr.microsoft.com/windows/nanoserver:1809' 
          }
        }
        stages {
          stage('Test') {
            steps {
              bat 'echo I am a temporary file >> temp.txt'
              bat 'type temp.txt'
            }
          }
        }
      }
      

      However, the temp.txt file I append to is getting longer and longer (as it's appended to with each build, and nothing deletes it), and indeed I can see it sitting in the filesystem on my agent node that runs Docker. For example, the console log shows this for my 4th build:

      00:00:04.251  C:\Jenkins\workspace\Sandbox\DockerTest>echo I am a temporary file  1>>temp.txt 
      00:00:04.259  [Pipeline] bat
      00:00:04.563  
      00:00:04.563  C:\Jenkins\workspace\Sandbox\DockerTest>type temp.txt 
      00:00:04.563  I am a temporary file 
      00:00:04.563  I am a temporary file 
      00:00:04.563  I am a temporary file 
      00:00:04.563  I am a temporary file 
      

      Am I missing something fundamental about how this is supposed to work? I had expected this syntax would result in the echo and type commands being run in a container that was then discarded, resulting in an entirely new temp.txt file each time, and nothing left over.

        Attachments

          Activity

          Hide
          medianick Nick Jones added a comment - - edited

          Ah, indeed I may have misunderstood how this works: the build is runningĀ 

          $ docker run -d -t -w C:/Jenkins/workspace/Sandbox/DockerTest/ -v C:/Jenkins/workspace/Sandbox/DockerTest/:C:/Jenkins/workspace/Sandbox/DockerTest/ -v C:/Jenkins/workspace/Sandbox/DockerTest@tmp/:C:/Jenkins/workspace/Sandbox/DockerTest@tmp/ -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** mcr.microsoft.com/windows/nanoserver:1809 cmd.exe
          

          This means the Docker is being instructed to mount the agent's workspace as a shared volume, which means that by design it's picking up whatever happens to be in that workspace (e.g., artifacts left over from previous builds). However, I cannot seem to clean the workspace using cleanWs() to remove those artifacts; if I try I get this:

          ERROR: Cannot delete workspace: Unable to delete 'C:\Jenkins\workspace\Sandbox\DockerTest'. Tried 3 times (of a maximum of 3) waiting 0.1 sec between attempts.
          0
          

          (It does actually delete the workspace, it seems, but it still fails the build.)

          As far as I can tell, my only automated recourse would be to leverage a Git checkout behavior such as "wipe out repository & force clone" to guarantee a fresh workspace. I'll consider that a separate issue.

          Show
          medianick Nick Jones added a comment - - edited Ah, indeed I may have misunderstood how this works: the build is runningĀ  $ docker run -d -t -w C:/Jenkins/workspace/Sandbox/DockerTest/ -v C:/Jenkins/workspace/Sandbox/DockerTest/:C:/Jenkins/workspace/Sandbox/DockerTest/ -v C:/Jenkins/workspace/Sandbox/DockerTest@tmp/:C:/Jenkins/workspace/Sandbox/DockerTest@tmp/ -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** mcr.microsoft.com/windows/nanoserver:1809 cmd.exe This means the Docker is being instructed to mount the agent's workspace as a shared volume, which means that by design it's picking up whatever happens to be in that workspace (e.g., artifacts left over from previous builds). However, I cannot seem to clean the workspace using cleanWs() to remove those artifacts; if I try I get this: ERROR: Cannot delete workspace: Unable to delete 'C:\Jenkins\workspace\Sandbox\DockerTest'. Tried 3 times (of a maximum of 3) waiting 0.1 sec between attempts. 0 (It does actually delete the workspace, it seems, but it still fails the build.) As far as I can tell, my only automated recourse would be to leverage a Git checkout behavior such as "wipe out repository & force clone" to guarantee a fresh workspace. I'll consider that a separate issue.
          Hide
          medianick Nick Jones added a comment -

          As noted in my previous comment, this seems to be the intended behavior, where the workspace from the agent node gets shared with the running container. I have a separate challenge in wiping the workspace effectively in this scenario, but it's not the bug I originally reported, so I'm closing this one.

          Show
          medianick Nick Jones added a comment - As noted in my previous comment, this seems to be the intended behavior, where the workspace from the agent node gets shared with the running container. I have a separate challenge in wiping the workspace effectively in this scenario, but it's not the bug I originally reported, so I'm closing this one.

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            medianick Nick Jones
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: