Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/windows agents with pathing issues fixed #184

Merged
merged 11 commits into from Oct 9, 2019

Conversation

jetersen
Copy link
Member

@jetersen jetersen commented Aug 23, 2019

resolve #148
resolve #183

This is what we had issues with b0d3fae when testing out the branch made by @rbutcher

We have been running this in production since November/December of last year 😓

Allows us to use a declarative pipeline like

For a windows docker host

pipeline {
  agent {
    docker {
      label 'windows'
      image 'mcr.microsoft.com/powershell'
    }
  }
}

For a linux docker host

pipeline {
  agent {
    docker {
      label 'linux'
      image 'python'
    }
  }
}

@jetersen jetersen mentioned this pull request Aug 23, 2019
@jetersen
Copy link
Member Author

@dwnusbaum perhaps it would be best to setup import order and codestyle to avoid fighting over imports 😆

@dwnusbaum
Copy link
Member

@Casz sure, if you want to open a PR to enforce some kind of import order, fine by me.

@henryborchers
Copy link

As someone who could REALLY USE Windows Docker agents, I'm extremely excited about this pull request. I've been wanting to integrate Windows docker agents for over a year now. However, I got so frustrated by the lack of interest from the maintainers of this plugin that I gave up waiting and started using bat commands to use it. @Casz, I really home you can get this PR accepted.

@nvx
Copy link

nvx commented Aug 26, 2019

I've just run into the limitation of this plugin that it doesn't support windows and am glad to see a PR ready to fix it.

Is there anything else needed before this can be merged? This would make a lot of things easier for me.

argb.add("-w", workdir);
}
for (Map.Entry<String, String> volume : volumes.entrySet()) {
argb.add("-v", volume.getKey() + ":" + volume.getValue());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use --mount instead?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, I notice the regular docker client uses volumes instead of mounts as well. Should probably keep them consistent (which I suspect means switching DockerClient.java to mounts too mind you - and a separate PR)

@jetersen
Copy link
Member Author

I'll properly end up spending the weekend fixing this up 😓

@@ -75,11 +75,17 @@ class Docker implements Serializable {
new Image(this, id)
}

String shell() {
node {
script.isUnix() ? "sh" : "bat"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to use powershell as the default for Windows based containers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

powershell or do you want pwsh? 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it looks like the powershell step currently only supports powershell.exe not pwsh.exe, so sticking with bat is the best option.

@slide
Copy link
Member

slide commented Sep 13, 2019

Big +1 from me on this one.

@jetersen
Copy link
Member Author

@slide I hope we can work on getting this tested in Jenkins CI :)

@slide
Copy link
Member

slide commented Sep 13, 2019

@Casz what do you need for that? We have a label 'windock' for windows docker agents.

@jetersen
Copy link
Member Author

Neat! All I would need, so good to know 😍

@slide
Copy link
Member

slide commented Sep 13, 2019

Looks like several of the tests need to be updated to run only on Linux systems.

@Nicabus
Copy link

Nicabus commented Sep 26, 2019

Click the button! We needses it! 😄

@tiger5226
Copy link

@Casz I know this might be a big ask, but is there a way you could write up some docs on how to use this branch in an instance of jenkins? Maybe you should just fork this repo and publish this plugin? I would certainly use it. You can call it the docker4win-workflow-plugin

@tiger5226
Copy link

I was actually able to get this repo forked, this PR merged, project build, and hpi file installed in jenkins in under a few hours. So not too bad at all. I can confirm...I have it working.

@Casz Not sure if it is related to this PR but I have to specify my registry instead of it assuming the global registry. So it inspects dockerhub first then tries my local repo. Not really a big deal though since it does try the globally referenced repo in the end. Again I doubt this is related, just wanted to mention it in case you it triggered something for you. Great work!

@oleg-nenashev
Copy link
Member

I am about releasing it if there is a consensus.

@jetersen
Copy link
Member Author

jetersen commented Oct 9, 2019

@rbutcher Thanks for doing all the heavy lifting! I just fixed up the path issues!

@oleg-nenashev thanks for making the release.

Release notes are available here https://github.com/jenkinsci/docker-workflow-plugin/releases/tag/docker-workflow-1.21

Thanks for all the work to enable release drafter and thanks @toolmantim just an all around thank you 😊

@jetersen jetersen deleted the features/windows_slaves branch October 9, 2019 18:56
@gegles
Copy link

gegles commented Oct 10, 2019

This is so great, thanks guys, it works!

One feature request though, could you also make it work with agent { dockefile {} } ?
Even though it would probably take a while the first time to build the image (with Windows+Build tools containers) that would be awesome as we define our builder images Dockerfiles within the project codebase.

@slide
Copy link
Member

slide commented Oct 10, 2019

@gegles Please file an issue in Jira at https://issues.jenkins.io. Adding additional comments to this PR is not really a good place to request features.

@jetersen
Copy link
Member Author

jetersen commented Oct 10, 2019

@gegles it should already work.

Labeling agents becomes very important :)

I build this pipeline last week and been working great:

#! /usr/bin/env groovy

pipeline {
    agent {
        dockerfile {
            filename "Dockerfile.CLI"
            label "windows"
        }
    }
    stages {
        stage('Nuget restore') {
            steps {
                powershell "dotnet restore --source https://artifactory.company.com/api/nuget/v3/nuget"
            }
        }
        stage('Build solution') {
            steps {
                powershell "dotnet build -c:Release --no-restore -v:m"
            }
            post {
                always {
                    //  MSBuild warnings publisher
                    recordIssues tools: [msBuild()], enabledForFailure: true, qualityGates: [
                        [threshold: 1, type: 'TOTAL', unstable: false]
                    ]
                }
            }
        }
        stage('Pack') {
            steps {
                powershell 'remove-item ./publish/ -Force -Recurse -ErrorAction SilentlyContinue'
                powershell "dotnet publish projectCLI/projectCLI.csproj -c:Release -v n --no-restore --output publish"
                zip dir: 'publish', zipFile: 'publish/project.zip'
                archiveArtifacts 'publish/*.zip' 
            }//steps
        }//stage
    }//stages
}//pipeline

@gegles
Copy link

gegles commented Oct 10, 2019

@Casz Thanks for your response. I tried again and here is what I see.

When I try using the following (with a pre-built image), it works:

stage('Windows') {

   agent {

      docker {

         image 'my-win-builder'

         label 'windows && docker && x86_64'

     }
}

When I try with the following:

stage('Windows') {

   agent {

      dockerfile {

         dir 'docker\\build\\windows'

         label 'windows && docker && x86_64'

     }
}

It fails with the classic Cannot run program "nohup" error.

Same issue if I move and rename my windows Dockerfile to the top-level dir:

stage('Windows') {

   agent {

      dockerfile {

         filename 'Dockerfile.Windows'

         label 'windows && docker && x86_64'

     }
}

Any thoughts?

@jetersen
Copy link
Member Author

jetersen commented Oct 10, 2019

oh it works for us because someone installed git with linux tools in our jenkins agent image 😓

cinst git --params \"/GitAndUnixToolsOnPath /SChannel\" -y --no-progress

I'll look into improving dockerfile then :)

@gegles
Copy link

gegles commented Oct 10, 2019

I see. Glad you figured out the root cause. Yes, much appreciated if you can sort this out! I am not knowledgeable enough about Jenkins internals to do it myself... Let me know if there is a specific ticket to track this.

Cheers. G.

@gegles
Copy link

gegles commented Oct 10, 2019

Ok, looking for a workaround, I've tried reinstalling git on our Windows agent the same way you did (and rebooted), but I still get the same error...

How do you guys connect Jenkins to the slave? we use ssh (even on windows).

@albertosottile
Copy link

@Casz Thank you very much for your efforts on this feature. Is it possible to use Windows containers also with the scripted pipeline syntax?

@jetersen
Copy link
Member Author

@albertosottile should be the same.

@gegles we use JNLP

@gegles
Copy link

gegles commented Oct 10, 2019

Ok, after some more trial and error, I got the workaround working by setting the DefaultShell for OpenSSH to the git bash shell:

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\Git\bin\bash.exe" -PropertyType String -Force

This will get us going for now. Thanks for all your work and for sharing.

@oleg-nenashev
Copy link
Member

oleg-nenashev commented Oct 10, 2019 via email

@solvingj
Copy link

Someone should tweet that this has been released, maybe Jenkins or cloudbees, we want to retweet.

@jetersen
Copy link
Member Author

@rbutcher
Copy link
Contributor

@Casz Thanks for taking this crusade over for me. After the chat over on my PR I thought this was dead in the water and have only been passively monitoring the progress of this. I was surprised when a buddy of mine at work told me this got merged yesterday. Crazy happy to see this merged. Thanks folks!

@bverkron
Copy link

It fails with the classic Cannot run program "nohup" error.

We ran into this as well. I had completely forgotten about it because I solved it while I was starting to refactor and rebuild the plugin myself before finding this PR.

I solved it via the following. Although this method is less ideal because it requires manual GUI steps. Powershell or other CLI methods are preferred for lots of reasons.

  • Right-click start menu > System > Advanced system settings > Environment variables > System variables (bottom section) > Select Path > Edit > New add this to a new entry C:\Program Files\Git\usr\bin
  • Log out / in or reboot

@jetersen
Copy link
Member Author

I don't want workarounds 😄 I want actual fixes and the PR is already up: jenkinsci/pipeline-model-definition-plugin#354

@bverkron
Copy link

Excellent! That's the right way for sure!

@bverkron
Copy link

We have been running this PR for over a year now with no issues 🤔

Thanks, that's all the confirmation I needed. We likely won't troubleshoot this or submit a bug report because cmd itself is pretty antiquated and I'd much prefer to use something like powershell as our default anyway.

Ran into some situations where we might be forced to use bat. Submitted this issue.
https://issues.jenkins-ci.org/browse/JENKINS-59893

@jetersen
Copy link
Member Author

jetersen commented Nov 5, 2019

@gegles should be solved in v1.4.0 of pipeline-model-definition

@gegles
Copy link

gegles commented Nov 7, 2019

It seems tobe working!! Thank you!

@penszo
Copy link

penszo commented Mar 18, 2020

Hi, so I'm trying to use it with latest version 1.23 of workflow plugin, and even with the simplest example of just running the container it fails to recognize that it is a windows not linux container:

Reason: Template provisioning failed.

com.github.dockerjava.api.exception.BadRequestException: {"message":"container 68e49ebb6925bc8c1f8ea92f2407843b6f94f35af8bc2c2ec5ad395c6efb0e9f encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: {\"CommandLine\":\"/bin/sh\",\"WorkingDirectory\":\"C:\\\\\",\"EmulateConsole\":true,\"CreateStdInPipe\":true,\"CreateStdOutPipe\":true,\"ConsoleSize\":[0,0]}"}

jenkins script:

pipeline {
    agent {
        docker {
            label 'windows'
            image 'win-docker-tests'
        }
    }
    stages {
        stage('Docker Test') {
            steps {
                powershell "dir"
            }
        }
    }
}

any thoughts?

please help.

@jetersen
Copy link
Member Author

jetersen commented Mar 18, 2020

@penszo please see the above comment above as there is a fix to that issue:
#184 (comment)
#184 (comment)

@penszo
Copy link

penszo commented Mar 18, 2020

@jetersen thanks for super fast response.

Regarding your comments - I'm using the latest 1.6.0 version of this plugin. Still doesn't work for me :( and this is such a nice feature. I would love to have it up and running.

@jetersen
Copy link
Member Author

@penszo I honestly only tested this using Windows Server 2019 since Microsoft recommends that for any docker workload

@marianob85
Copy link

Hi, so I'm trying to use it with latest version 1.23 of workflow plugin, and even with the simplest example of just running the container it fails to recognize that it is a windows not linux container:

Reason: Template provisioning failed.

com.github.dockerjava.api.exception.BadRequestException: {"message":"container 68e49ebb6925bc8c1f8ea92f2407843b6f94f35af8bc2c2ec5ad395c6efb0e9f encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: {\"CommandLine\":\"/bin/sh\",\"WorkingDirectory\":\"C:\\\\\",\"EmulateConsole\":true,\"CreateStdInPipe\":true,\"CreateStdOutPipe\":true,\"ConsoleSize\":[0,0]}"}

jenkins script:

pipeline {
    agent {
        docker {
            label 'windows'
            image 'win-docker-tests'
        }
    }
    stages {
        stage('Docker Test') {
            steps {
                powershell "dir"
            }
        }
    }
}

any thoughts?

please help.

@penszo Did you find a solution for this problem ? I'm struggling with the same problem on windows docker. Jenkins report:

com.github.dockerjava.api.exception.BadRequestException: {"message":"container f18410e6599a71a79288cea971da012df56ff85c64f363b8c5f20908d11201af encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)\n[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]\n[Event Detail: Provider: 00000000-0000-0000-0000-000000000000]\n[Event Detail: onecore\\vm\\compute\\management\\orchestration\\vmhostedcontainer\\processmanagement.cpp(173)\\vmcomputeagent.exe!00007FF753C89F4B: (caller: 00007FF753C3E13A) Exception(2) tid(394) 80070002 The system cannot find the file specified.\r\n CallContext:[\\Bridge_ProcessMessage\\VmHostedContainer_ExecuteProcess] \n Provider: 00000000-0000-0000-0000-000000000000] extra info: {\"CommandLine\":\"/bin/sh\",\"WorkingDirectory\":\"C:\\\\tmp\",\"Environment\":{\"COMPLUS_NGenProtectedProcess_FeatureEnabled\":\"0\",\"NUGET_VERSION\":\"5.8.1\",\"ROSLYN_COMPILER_LOCATION\":\"C:\\\\Program Files (x86)\\\\Microsoft Visual Studio\\\\2019\\\\BuildTools\\\\MSBuild\\\\Current\\\\Bin\\\\Roslyn\"},\"EmulateConsole\":true,\"CreateStdInPipe\":true,\"CreateStdOutPipe\":true,\"ConsoleSize\":[0,0]}"} at

@jglick jglick mentioned this pull request Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet