Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
My base MSBuild image
FROM microsoft/windowsservercore
# Pass in JENKINS_SECRET and JENKINS_JNLP_URL as an environment variables
# Install jre and add to PATH
# Do not recommend pushing the image to a public repository due to Oracle's EULA:
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN wget '' -Outfile 'C:\jreinstaller.exe' ; \
Start-Process -filepath C:\jreinstaller.exe -passthru -wait -argumentlist "/s,INSTALLDIR=c:\Java\jre1.8.0_91" ; \
del C:\jreinstaller.exe
ENV JAVA_HOME c:\\Java\\jre1.8.0_91
# Install msbuild (vs2017) and add to PATH
RUN Invoke-WebRequest "" -OutFile vs_BuildTools.exe -UseBasicParsing ; \
Start-Process -FilePath 'vs_BuildTools.exe' -ArgumentList '--quiet', '--norestart', '--locale en-US' -Wait ; \
Remove-Item .\vs_BuildTools.exe ; \
Remove-Item -Force -Recurse 'C:\Program Files (x86)\Microsoft Visual Studio\Installer'
RUN setx /M PATH $($Env:PATH + ';' + ${Env:ProgramFiles(x86)} + '\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin')
# Install git through chocolatey and add git to the path
ENV chocolateyUseWindowsCompression false
RUN iex ((new-object net.webclient).DownloadString('')); \
choco install -v -y git
RUN setx /M PATH $($Env:PATH + ';' + 'C:\Program Files\Git\usr\bin')
# Pass in the base url of the master node while building
ENV HOME C:\Jenkins
# Get Jenkins slave jar
RUN (New-Object System.Net.WebClient).DownloadFile('{0}/jnlpJars/slave.jar' -f $env:BASE_URL, 'slave.jar') ;
# For some reason just using C:\Jenkins does not work - it tries to map to \ContainerVolumes in k8s. The workaround is to mount the folder as a drive and use it as the working directory for builds
RUN set-itemproperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices' -Name 'G:' -Value '\??\C:\Jenkins' -Type String
ENTRYPOINT C:\Java\jre1.8.0_91\bin\java.exe -jar C:\slave.jar -jnlpUrl $env:JENKINS_JNLP_URL -secret $env:JENKINS_SECRET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.