Azure DevOps build c++ project using custom docker image from docker hub

0

My goal is to build a c++ project that I have on bitbucket using the Azure DevOps pipelines in a windows environment using the Microsoft Visual Studio c++ compiler.

Since my project is a complex one with some dependencies, I figured that it should be built using a docker image. To compile my project I use CMake, so I took a msvc-2019 docker and added CMake (I know the original one already has CMake as a part of the Microsoft Visual Studio c++ optional tools, but for testing, I needed to download and install some package). If I run this docker image locally from my computer, I can compile and run the c++ example project. For this, I run the docker image from the windows Docker Desktop application and then open a CLI to that running docker image. Once I am in the docker, I do:

git clone http://bitbucket.org/apalomer/window_docker_azuredevops_example.git
cd window_docker_azuredevops_example
mkdir build
cd build
cmake ..
cmake --build . --config RelWithDebInfo
RelWithDebInfo\hello_world.exe

Which produces the output:

C:\window_docker_azuredevops_example\build>cmake ..
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.17763.
-- The CXX compiler identification is MSVC 19.27.29111.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.291
10/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/window_docker_azuredevops_example/build

C:\window_docker_azuredevops_example\build>cmake --build . --config RelWithDebInfo
Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Checking Build System
  Building Custom Rule C:/window_docker_azuredevops_example/CMakeLists.txt
  hello_world.cpp
  hello_world.vcxproj -> C:\window_docker_azuredevops_example\build\RelWithDebInfo\hello_world.exe
  Building Custom Rule C:/window_docker_azuredevops_example/CMakeLists.txt

C:\window_docker_azuredevops_example\build>RelWithDebInfo\hello_world.exe
hello world

So the virtual environment works fine.

Now that the docker image works, I created a project in Azure DevOps and created a new pipeline. During the pipeline creation, I select Bitbucket Cloud as my source, I select the right repository and select the azure-pipelines.yml file in it. The content of the file is the following:

# C/C++ with GCC
# Build your C/C++ project with GCC using make.
# Add steps that publish test results, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/c-cpp/gcc

trigger:
- master
- hotfix/*
- release/*

pool:
  vmImage: 'windows-2019'

container: apalomer/windows:msvc-2019

steps:
- script: |
    mkdir build
    cd build
    cmake ..
    cmake --build . --config RelWithDebInfo
    RelWithDebInfo\hello_world.exe
  displayName: 'hello world compilation'

However, the pipeline fails to build with the following error:

-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.17763.
CMake Error at CMakeLists.txt:3 (project):
  Failed to run MSBuild command:

    C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe

  to get the value of VCTargetsPath:

    Exit code 0xc0000142
    



-- Configuring incomplete, errors occurred!

Which in my head makes no sense, as the docker image used has the right software installed, and the vcvarsall.bat x64 should have been called as the DockerFile ends with CMD ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat","x64","&&","cmd.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"].

Can somebody point me out on what am I doing wrong?

P.S. The given example project does not have any dependency, however, it illustrates my problem, and once it works, it will not be a complex task to build a new docker image with the right dependencies.

c++
azure
docker
dockerfile
docker-for-windows
asked on Stack Overflow Oct 20, 2020 by apalomer • edited Oct 20, 2020 by apalomer

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0