简体   繁体   中英

Pre-build task of Visual Studio project fails in GitLab Runner

I have written a Python3 script that creates some Qt resource (.rcc) and header files (.h) .

Because this script will be executed on both Windows and macOS, I have based the Qt tool path on an environment variable, called QTBIN which points to the binary folder within the Qt installation folder.

So far all is good when calling the script manually in the terminal (both Windows and Mac).

Then I added the script as a pre-build event in Visual Studio 2019:

python $(ProjectDir)Scripts\generateQtUI.py

So far, all is good. It gets executed by Visual Studio and Xcode when running locally.

Now, as we are using a GitLab build server to build both projects this should be just fine. This is the msbuild command executed by the Windows GitLab Runner:

- msbuild -m project.sln /t:project /p:Configuration=Debug /p:Platform=x64 /p:PreferredToolArchitecture=x64 -noWarn:C4244 -noWarn:C4267 -noWarn:C4099 -noWarn:C4305 -noWarn:C4018

However, both the macOS and Windows build server is complaining. I have of course added the new environment variable to both the build servers.

The windows build server returns this error log snippet:

        C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(139,5): error MSB3073: The command "python C:\GitLab-Runner\builds\Uthz1X_B\0\company\product\Scripts\generateQtUI.py [C:\GitLab-Runner\builds\Uthz1X_B\0\company\product\project.vcxproj]
        C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(139,5): error MSB3073:  [C:\GitLab-Runner\builds\Uthz1X_B\0\company\product\project.vcxproj]
        C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(139,5): error MSB3073: :VCEnd" exited with code 9020. [C:\GitLab-Runner\builds\Uthz1X_B\0\company\product\project.vcxproj]
     200 Warning(s)
     1 Error(s)
 Time Elapsed 00:01:10.92
 ERROR: Job failed: exit status 1

It looks like the scripts don't even gets started as it has its own output which usually gets written to the console.

The GitLab runner instance on Windows is set up with a shell executor and the shell is Powershell.

Any ideas of why the build server fails to build the solution?

NOTE : Windows build server and development computer are the same machines in this case.


Additional tests

I have tried to call a HelloPython.py script directly from the build job configuration. This returns a permission error telling that the job does not have access to a TEMP folder although the GitLab Runner is installed as a service with default configuration (root user).

$ whoami
 nt authority\system
$ python Scripts/HelloPython.py
 Program 'python.exe' failed to run: Systemet kan ikke f� adgang til filenAt C:\WINDOWS\TEMP\build_script885294397\scrip
 t.ps1:183 char:1
 + python Scripts/HelloPython.py
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
 At C:\WINDOWS\TEMP\build_script885294397\script.ps1:183 char:1
 + python Scripts/HelloPython.py
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
     + FullyQualifiedErrorId : NativeCommandFailed

 ERROR: Job failed: exit status 1

Alright, I did not see this come: The permission problem turned out to be the Python installation. It was only installed for current user - not all users. During the installation I had chosen: Install Python Launcher for all users. This did not allow all users to use Python though

To fix this I reinstalled Python, chose custom install and selected the option: All users.

This turned out to be the solution for the GitLab build job as well.

Lesson learned

  1. Always make sure that "install for all users" is actually for the expected software.
  2. Do not dig too deep into the error message - it might be wrong or misleading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM