Docker: Jenkins Build Server on Windows Server Core
Big fan of Jenkins! I’ve really enjoyed the flexibility that this CI server provides. While it’s easy to run a Linux container with Jenkins and do .NET Core builds it’s not possible to build traditional ASP.NET projects… unless you install Mono.. but I could never get that to work. After contemplating my options, I decided to try and set up Jenkins on a Docker Windows Server Core image.
This script installs ASP.NET, .NET Core, Java, and Jenkins on a Windows Server Core image.
GitHub: Docker Windows Server Jenkins
WARNING: this post is a work in progress. The current Dockerfile builds and creates a Windows Server with Jenkins but there are still some issues with this process.
Dockerfile
This dockerfile builds off the Windows Server Core image.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
FROM mcr.microsoft.com/windows/servercore:1809-amd64 LABEL maintainer="@mrjamiebowman" WORKDIR / # set up dirs RUN mkdir C:\setup RUN mkdir C:\jenkins RUN mkdir C:\Java\jre1.8.0_202\bin # paths RUN SetX PATH "%path%;C:\Program Files\7-zip;C:\Java\jre1.8.0_202\bin" RUN SetX JAVA_HOME 'C:\Java\jre1.8.0_202' # set working directory WORKDIR /setup # 7zip COPY installers/7z1602-x64.exe /setup/ RUN powershell -Command "Start-Process -Wait -FilePath 'C:\setup\7z1602-x64.exe' -ArgumentList '/S'" # install jre 8 WORKDIR /Java/ COPY installers/jre-8u202-windows-x64.tar.gz /Java/ RUN 7z.exe e jre-8u202-windows-x64.tar.gz -y RUN 7z.exe x jre-8u202-windows-x64.tar -y # install chocolatey RUN powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" # install apps WORKDIR /setup # install asp.net 4.8 developer pack COPY installers/ndp48-devpack-enu.exe /setup/ RUN ndp48-devpack-enu.exe /q /install # install .net core 3.1 COPY installers/dotnet-sdk-3.1.301-win-x64.exe /setup/ RUN dotnet-sdk-3.1.301-win-x64.exe /q /install # set up jenkins ENV HOME /jenkins ENV JENKINS_VERSION 2.0 RUN powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://updates.jenkins-ci.org/download/war/2.0/jenkins.war', '/jenkins/jenkins.war');" EXPOSE 8080 EXPOSE 50000 # entrypoint COPY entrypoint.bat /setup/ ENTRYPOINT /setup/entrypoint.bat |
Entrypoint
I ran into an issue where executing the jar file did not keep the process running in the foreground. I’m not sure why… However, for the sake of time I used ping -t localhost
to keep the container running. This seemed to work.
1 2 |
java -jar C:\jenkins\jenkins.war ping -t localhost |