Using the EC2 Plugin for Jenkins to Build On Demand Windows Slaves

Building a linux slave with jenkins is straight forward. I can do that any day without problems. One of our problems was building windows slaves using the EC2 plugin. We could never get it to work, we thought there were bugs that just didn’t let us. It does and here’s how todo it.

For US, we continually improve and build/rebuild our ami’s we do so using packer.. For this tutorial you’re going to need packer installed.

One of the gotchas that had us stuck is the EC2 Plugin uses WINRM and SMB to configure. It does not support anything but SMB1… SMB1 on modern operating systems is disabled so we’ll have to re-enable it. Jenkins will communicate with the AMI on 445, 5985, and 5986.

I’ll assume you’ve used packer before and have a configured AWS API Key.

Take a clone of this repo

In the repo there’s a few files you’re going to need to edit.

  1. Launch-Config.json
    • You’ll need to change the static password for windows to something that suits your environment (yes, this has to be static)
  2. win2016-jenkins-slave.json
    • Edit: the variables at the top.

You’re now ready to trigger a build. Assuming Packer is in your path you can execute it by typing

packer build -debug win2016-jenkins-slave.json

*I put debug in but its not needed.

At this point you can go grab a coffee and wait a bit, until Packer builds your AMI.

Once that’s done, head over to Jenkins and add it to your config. In our testing we found a boot delay of 7.5 worked well.

You should now have a working windows AMI for jenkins.