dockergitlabwindows-serverwindows-containernano-server

"nmake : The term 'nmake' is not recognized:" in WindowsContainer running in GitLab


I am trying to create a Windows Container which includes C++ compilers and libraries to build our software in GitLab.

This is my Dockerfile to create the windows-build-base container:

# escape=`
# based on https://learn.microsoft.com/de-de/visualstudio/install/build-tools-container?view=vs-2022
FROM mcr.microsoft.com/windows/servercore:ltsc2022

SHELL ["cmd", "/S", "/C"]

USER ContainerAdministrator

RUN `
    curl -SL --output vs_buildtools.exe https://aka.ms/vs/15/release/vs_buildtools.exe `
    `
    && (start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
        --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools" `
        --add Microsoft.VisualStudio.Component.Roslyn.Compiler `
        --add Microsoft.Component.MSBuild `
        --add Microsoft.VisualStudio.Component.CoreBuildTools `
        --add Microsoft.VisualStudio.Workload.MSBuildTools `
        --add Microsoft.VisualStudio.Component.Windows10SDK `
        --add Microsoft.VisualStudio.Component.VC.CoreBuildTools `
        --add Microsoft.VisualStudio.Component.Static.Analysis.Tools `
        --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
        --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest `
        --add Microsoft.VisualStudio.Component.Windows10SDK.17763 `
        --add Microsoft.VisualStudio.Component.VC.CMake.Project `
        --add Microsoft.VisualStudio.Component.TestTools.BuildTools `
        --add Microsoft.VisualStudio.Component.VC.ATL `
        --add Microsoft.VisualStudio.Component.VC.ATLMFC `
        --add Microsoft.Net.Component.4.6.1.SDK `
        --add Microsoft.Net.Component.4.6.1.TargetingPack `
        --add Microsoft.VisualStudio.Component.VC.CLI.Support `
        --add Microsoft.VisualStudio.Workload.VCTools `
        || IF "%ERRORLEVEL%"=="3010" EXIT 0) `
    `
    && del /q vs_buildtools.exe

RUN tree /f C:\BuildTools

RUN `
    curl -SL --output git.exe "https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.3/Git-2.41.0.3-64-bit.exe" `
    && (start /w git.exe /SP- /VERYSILENT /NORESTART /NOCANCEL /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS) `
    && del /q git.exe

RUN setx /M PATH "%PATH%;C:\Program Files\Git\bin"

USER ContainerUser

ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

As mentioned in this Dockerfile I used https://learn.microsoft.com/de-de/visualstudio/install/build-tools-container?view=vs-2022 as the example but took VS2017 instead.

My GitLab job looks like this:

build:
  image: registry.my.company.com/windows-build-base:1.0
  stage: build
  tags:
    - windows-agent
  variables:
    BZ2_SRC_DIR: C:\bin\src\bzip2
  script:
    - git clone --branch=$BZ2_VERSION git://sourceware.org/git/bzip2.git $BZ2_SRC_DIR
    - cd $BZ2_SRC_DIR
    - nmake -f makefile.msc

But it is not able to find nmake. I added some debug outputs to verify its existence. nmake is available, but the entrypoint does not seem to work. Calling VsDevCmd.bat directly in the GitLab pipeline does not work either.

How do I add the VS vars without spawning a new shell and making it available in my GitLab job script?


Solution

  • Since I have not found a solution to this, I printed all environment variables in cmd and a second time in x64 Native Tools Command Prompt for VS 2017. I got the diff and added those environment variables by hand.

    This is not an ideal solution but it is a working one.