appveyor / ci

AppVeyor community support repository
https://www.appveyor.com
344 stars 64 forks source link

Wrong path to Hosts file on Windows #3831

Open 0xShkk opened 1 year ago

0xShkk commented 1 year ago

When I try to add a hosts file entry to my Windows build environment via

hosts:

  hostname.com: 192.168.44.125

in the yaml file, the build fails with the following error:

Could not find a part of the path 'C:\Windows\drivers\etc\hosts'.

Seems like a bug to me as the path to the hosts file on Windows is:

C:\Windows\System32\drivers\etc\hosts

FeodorFitsner commented 1 year ago

What build image do you use? Could you drop a link to your build please (if it's open source of course)?

0xShkk commented 1 year ago

I use a custom build image for which I cannot disclose the full source unfortunately. It is based on mcr.microsoft.com/windows/servercore:ltsc2019 Everything else works with that image.

Is there anything I should take care of during the build process of the image which could have provoked this error?

FeodorFitsner commented 1 year ago

AppVeyor agent uses this call to get the location of System32 folder:

Environment.GetFolderPath(Environment.SpecialFolder.System)

Which should usually return:

C:\Windows\System32

https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-6.0

0xShkk commented 1 year ago

When I start my Docker build image and do the equivalent in PowerShell (inside the container)

[Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)

The output is

C:\Windows\system32

Maybe a AppVeyor agent bug?

FeodorFitsner commented 1 year ago

Try adding this command to the beginning of your build to get the value of all vars:

init:
- set
0xShkk commented 1 year ago

This is my snippet of the init command

init:
- ps: >-
    dir env:

And the output is:

Name                           Value                                           
----                           -----                                           
7zip                           "C:\Program Files\7-Zip\7z.exe"                 
ALLUSERSPROFILE                C:\ProgramData                                  
APPDATA                        C:\Users\ContainerAdministrator\AppData\Roaming 
APPVEYOR                       true                                            
APPVEYOR_ACCOUNT_NAME          AppVeyor                                        
APPVEYOR_API_URL               http://localhost:49156/                         
APPVEYOR_BUILD_AGENT_MODE      Docker                                          
APPVEYOR_BUILD_AGENT_PROJEC... C:\Users\ContainerAdministrator\Desktop\PROJECTNAME
APPVEYOR_BUILD_AGENT_VERSION   7.0.2417                                        
APPVEYOR_BUILD_BIN_FOLDER      C:\appveyor\bin                                 
APPVEYOR_BUILD_FOLDER          C:\Users\ContainerAdministrator\Desktop\PROJECTNAME
APPVEYOR_BUILD_ID              83                                              
APPVEYOR_BUILD_NUMBER          14                                              
APPVEYOR_BUILD_VERSION         x64-master.14                                   
APPVEYOR_BUILD_WORKER_IMAGE    WinPyCompiler                                   
APPVEYOR_CONSOLE_DISABLE_PTY   true                                            
APPVEYOR_ENVIRONMENT           build-agent                                     
APPVEYOR_FORCED_BUILD          True                                            
APPVEYOR_JOB_ID                8u78pmun73j9bv4t                                
APPVEYOR_JOB_NUMBER            1                                               
APPVEYOR_PROJECT_ID            4                                               
APPVEYOR_PROJECT_NAME          PROJECTNAME                                        
APPVEYOR_PROJECT_SLUG          PROJECTNAME-v7y5x                                  
APPVEYOR_REPO_BRANCH           master                                          
APPVEYOR_REPO_COMMIT           8b1a99f7c715702eafe3a24851817bb64721b156        
APPVEYOR_REPO_COMMIT_AUTHOR    REDACTED                                         
APPVEYOR_REPO_COMMIT_AUTHOR... REDACTED    
APPVEYOR_REPO_COMMIT_MESSAGE   REDACTED
APPVEYOR_REPO_COMMIT_MESSAG... REDACTED             
APPVEYOR_REPO_COMMIT_TIMESTAMP 2022-07-09T00:37:59.0000000Z                    
APPVEYOR_REPO_NAME             BuildAutomation/PROJECTNAME                        
APPVEYOR_REPO_PROVIDER         gitea                                           
APPVEYOR_REPO_SCM              git                                             
APPVEYOR_REPO_TAG              false                                           
APPVEYOR_URL                   http://172.27.32.1:80/                          
APPVEYOR_WORKER_ID             18e63032a36b495b83ae107953beaa1c                
ChocolateyInstall              C:\ProgramData\chocolatey                       
ChocolateyLastPathUpdate       133021060905822818                              
CI                             true                                            
CI_LINUX                       false                                           
CI_MACOS                       false                                           
CI_WINDOWS                     true                                            
CommonProgramFiles             C:\Program Files\Common Files                   
CommonProgramFiles(x86)        C:\Program Files (x86)\Common Files             
CommonProgramW6432             C:\Program Files\Common Files                   
COMPUTERNAME                   EEF22CB8D0DC                                    
ComSpec                        C:\Windows\system32\cmd.exe                     
DriverData                     C:\Windows\System32\Drivers\DriverData          
ENABLENUGETPACKAGERESTORE      true                                            
FPS_BROWSER_APP_PROFILE_STRING Internet Explorer                               
FPS_BROWSER_USER_PROFILE_ST... Default                                         
GiteaPasswordHTTP              REDACTED        
GiteaUserHTTP                  REDACTED                                      
HOMEDRIVE                      C                                               
HOMEPATH                       \Users\ContainerAdministrator                   
LOCALAPPDATA                   C:\Users\ContainerAdministrator\AppData\Local   
NUMBER_OF_PROCESSORS           2                                               
OS                             Windows_NT                                      
Path                           C:\Program Files\AppVeyor\BuildAgent;C:\Pytho...
PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;....
POWERSHELL_DISTRIBUTION_CHA... MSI:Windows Server 2019 Datacenter              
PROCESSOR_ARCHITECTURE         AMD64                                           
PROCESSOR_IDENTIFIER           Intel64 Family 6 Model 85 Stepping 7, Genuine...
PROCESSOR_LEVEL                6                                               
PROCESSOR_REVISION             5507                                            
ProgramData                    C:\ProgramData                                  
ProgramFiles                   C:\Program Files                                
ProgramFiles(x86)              C:\Program Files (x86)                          
ProgramW6432                   C:\Program Files                                
PSExecutionPolicyPreference    Bypass                                          
PSModulePath                   C:\Users\ContainerAdministrator\Documents\Win...
PUBLIC                         C:\Users\Public                                 
SystemDrive                    C:                                              
SystemRoot                     C:\Windows                                      
TEMP                           C:\Users\ContainerAdministrator\AppData\Local...
TMP                            C:\Users\ContainerAdministrator\AppData\Local...
USERDOMAIN                     User Manager                                    
USERNAME                       ContainerAdministrator                          
USERPROFILE                    C:\Users\ContainerAdministrator                 
windir                         C:\Windows     
FeodorFitsner commented 1 year ago

OK, could you run [Environment]::GetFolderPath([System.Environment+SpecialFolder]::System) in the same manner during the build please?

0xShkk commented 1 year ago

Sure. Outcome is the same as in the container which I tested manually before...

init:
- ps: >-
    [Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)

Output during build:

Job started
Running "init" scripts
[Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)
C:\Windows\system32
Could not find a part of the path 'C:\Windows\drivers\etc\hosts'.
0xShkk commented 1 year ago

The last line is the Host entry modification via the AppVeyor GUI obviously

FeodorFitsner commented 1 year ago

Alright, does your image has .NET Core installed? If it does I'm thinking maybe we could try building and running .NET Core program displaying the value of that folder during the build or run a pre-built .NET Core app, something like this: https://gist.github.com/FeodorFitsner/3b79fd2b0638632804a656c5d86451c7

0xShkk commented 1 year ago

Did as you suggested.

Used this for the test

- dotnet --version
- mkdir test
- cd test
- dotnet new console
- type test.csproj
- echo "using System;namespace MyApp{internal class Program{static void Main(string[] args){Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.System));}}}" > Program.cs
- dotnet run

and this is the outcome during build.............

2.2.402

    Directory: C:\Users\ContainerAdministrator\Desktop

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        7/17/2022  11:09 AM                test

The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on C:\Users\ContainerAdministrator\Desktop\test\test.csproj...
  Restore completed in 138.54 ms for C:\Users\ContainerAdministrator\Desktop\test\test.csproj.

Restore succeeded.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

</Project>

C:\Windows\system32
0xShkk commented 1 year ago

Do you inspect this issue still?

FeodorFitsner commented 1 year ago

Still working on the repro. In the meantime to configure a host you could just append a new line to etc\hosts file in say "init" section of your build.