防止 Gitlab 在启动 docker 容器时将 -NoProfile 添加到 PowerShell
Prevent Gitlab adding -NoProfile to PowerShell when starting a docker container
1.如何防止 Gitlab 在创建 docker 容器时添加 -NoProfile?
2。使用带 -NoProfile 和不带 -NoProfile 的 powershell 有什么区别?
3。如果我 运行 powershell -NoProfile 以某种方式 load/run 默认配置文件并恢复设置 -NoProfile 标志的效果,有什么办法吗?
现在这些问题背后的故事:
MSBuild(Visual Studio 构建工具命令)在 Gitlab 使用 Powershell -NoProfile 启动的 docker 容器中使用时无法构建 Xamarin 应用程序。
我为 CI 创建了一个 docker 图像,如果我手动 运行 容器,一切正常,但是当它 运行 在 Gitlab 运行ner 作业,它失败了(更确切地说 msbuild /t:SignAndroidPackage 失败,因为某些文件没有生成)。我检查了这个(在 gitlab-ci.yml 中睡了 1 小时并附加到 运行ner 机器上的容器)并发现 Gitlab 使用 PowerShell -NoProfile 启动容器......我试过了手动(使用 -NoProfile 启动容器)我重现了这个问题。
错误是:
Could not find a part of the path 'C:\builds\gitlab\HMI.Framework\KDI\sub\HostApplicationToolkit\sub\KBle\KBle\sub\XamarinBluetooth\Source\Plugin.BLE.Android\Resources\Resource.Designer.cs'
此处缺少 Resource.Designer.cs(它应该在构建过程中自动生成)
这是docker文件:
# escape=`
# Use the latest Windows Server Core image with .NET Framework 4.8.
FROM mcr.microsoft.com/dotnet/framework/sdk:3.5-windowsservercore-ltsc2019
ENV VS_STUDIO_INSTALL_LINK=https://download.visualstudio.microsoft.com/download/pr/befdb1f9-8676-4693-b031-65ee44835915/c541feeaa77b97681f7693fc5bed2ff82b331b168c678af1a95bdb1138a99802/vs_Community.exe
ENV VS_INSTALLER_PATH=C:\TEMP\vs2019.exe
ENV ANDROID_COMPILE_SDK=29
# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]
ADD $VS_STUDIO_INSTALL_LINK $VS_INSTALLER_PATH
RUN %VS_INSTALLER_PATH% --quiet --wait --norestart --nocache --includeRecommended --includeOptional`
--add Microsoft.VisualStudio.Workload.NetCrossPlat `
--add Microsoft.VisualStudio.Workload.XamarinBuildTools `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
RUN del %VS_INSTALLER_PATH%
# set some util paths
RUN setx JAVA_HOME "c:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\"
RUN setx path "%path%;c:\Program Files (x86)\Android\android-sdk\tools\bin;c:\Program Files (x86)\Android\android-sdk\platform-tools"
# update android SDK with API 29
RUN echo y| sdkmanager "platforms;android-%ANDROID_COMPILE_SDK%"
#ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
这是gitlab-ci.yml
image: visualstudio2019-xamarin-ci:1.0-windowsservercore-ltsc2019
stages:
- build
- test
variables:
GIT_SUBMODULE_STRATEGY: 'recursive'
build_kdi:
stage: build
only:
- CI_CD
tags:
- docker-windows
script:
- '& "C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\Bin\MSBuild.exe" ./src/KDI/KDI.sln /t:Restore /p:AndroidBuildApplicationPackage=true /p:Configuration=Release'
- '& "C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\Bin\MSBuild.exe" /p:Configuration=Release /t:SignAndroidPackage /property:SolutionDir="C:\builds\gitlab\HMI.Framework\KDI\src\KDI\" /p:AndroidSigningKeyStore="C:\builds\gitlab\HMI.Framework\KDI\distribution\Android\KrohneAndroidKeystore.keystore" .\src\KDI\KDI\KDI.Android\KDI.Android.csproj'
run_bb_tests:
stage: test
only:
- CI_CD
tags:
- docker-windows
script:
- docker-ci/install_and_run_bb_tests.bat "phone_ip" "5555" arg1 arg2 || true
- adb pull /storage/emulated/0/Android/data/myApp/files/Exports/BBT_Exports/BBTests_CI C:\test_results
artifacts:
paths:
- c:\test_results\BBTests_CI #expire in 1 month by default
如果我使用以下方式启动此图像:docker 运行 -it myImage powershell 一切正常,但如果我 运行 它 docker 运行 -it myImage powershell -NoProfile,msbuild 在构建 xamarin 应用程序的某个步骤失败
- How can I prevent Gitlab from adding -NoProfile when creating the docker container?
显然你不能...还 but there is a feature request in place
- What's the difference between using powershell with -NoProfile and without it?
PowerShell 配置文件只是一个包含特定用户自定义功能等内容的文件。例如,如果我的 PowerShell 配置文件中包含 Function Banana(){Write-Host "Awesome"}
,例如 $Home[My]Documents\PowerShell\Profile.ps1。每当我打开 PowerShell 时,它都会自动加载该功能。所以我可以打开 PowerShell,键入 banana
并将字符串 Awesome
写入标准输出。如果我用 -NoProfile 启动 powershell,然后输入 banana
,我会得到 CommandNotFoundException
。
source
- Is there any way if I run powershell -NoProfile to somehow load/run the default profile and to revert the effect of setting -NoProfile flag?
也许吧。我只是说也许是因为我没有亲自测试过它,但理论上它应该有效。如果配置文件在容器中,您所要做的就是点源它。
. "C:\path\to\powershell\profile.ps1"
dot sourcing .ps1 文件将 运行 当前范围内的任何内容,其中包括加载函数(如果存在)。
dot source docs
我在 Gitlab 上的专业知识有限,但由于我对 Windows 容器、PowerShell 的整体经验以及 PowerShell 配置文件的性质,我怀疑配置文件是这个问题的根本原因,但我没有足够的 information/evidence 来明确地说。希望这在某种程度上有所帮助!
1.如何防止 Gitlab 在创建 docker 容器时添加 -NoProfile?
2。使用带 -NoProfile 和不带 -NoProfile 的 powershell 有什么区别?
3。如果我 运行 powershell -NoProfile 以某种方式 load/run 默认配置文件并恢复设置 -NoProfile 标志的效果,有什么办法吗?
现在这些问题背后的故事:
MSBuild(Visual Studio 构建工具命令)在 Gitlab 使用 Powershell -NoProfile 启动的 docker 容器中使用时无法构建 Xamarin 应用程序。
我为 CI 创建了一个 docker 图像,如果我手动 运行 容器,一切正常,但是当它 运行 在 Gitlab 运行ner 作业,它失败了(更确切地说 msbuild /t:SignAndroidPackage 失败,因为某些文件没有生成)。我检查了这个(在 gitlab-ci.yml 中睡了 1 小时并附加到 运行ner 机器上的容器)并发现 Gitlab 使用 PowerShell -NoProfile 启动容器......我试过了手动(使用 -NoProfile 启动容器)我重现了这个问题。
错误是:
Could not find a part of the path 'C:\builds\gitlab\HMI.Framework\KDI\sub\HostApplicationToolkit\sub\KBle\KBle\sub\XamarinBluetooth\Source\Plugin.BLE.Android\Resources\Resource.Designer.cs'
此处缺少 Resource.Designer.cs(它应该在构建过程中自动生成)
这是docker文件:
# escape=`
# Use the latest Windows Server Core image with .NET Framework 4.8.
FROM mcr.microsoft.com/dotnet/framework/sdk:3.5-windowsservercore-ltsc2019
ENV VS_STUDIO_INSTALL_LINK=https://download.visualstudio.microsoft.com/download/pr/befdb1f9-8676-4693-b031-65ee44835915/c541feeaa77b97681f7693fc5bed2ff82b331b168c678af1a95bdb1138a99802/vs_Community.exe
ENV VS_INSTALLER_PATH=C:\TEMP\vs2019.exe
ENV ANDROID_COMPILE_SDK=29
# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]
ADD $VS_STUDIO_INSTALL_LINK $VS_INSTALLER_PATH
RUN %VS_INSTALLER_PATH% --quiet --wait --norestart --nocache --includeRecommended --includeOptional`
--add Microsoft.VisualStudio.Workload.NetCrossPlat `
--add Microsoft.VisualStudio.Workload.XamarinBuildTools `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
RUN del %VS_INSTALLER_PATH%
# set some util paths
RUN setx JAVA_HOME "c:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\"
RUN setx path "%path%;c:\Program Files (x86)\Android\android-sdk\tools\bin;c:\Program Files (x86)\Android\android-sdk\platform-tools"
# update android SDK with API 29
RUN echo y| sdkmanager "platforms;android-%ANDROID_COMPILE_SDK%"
#ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
这是gitlab-ci.yml
image: visualstudio2019-xamarin-ci:1.0-windowsservercore-ltsc2019
stages:
- build
- test
variables:
GIT_SUBMODULE_STRATEGY: 'recursive'
build_kdi:
stage: build
only:
- CI_CD
tags:
- docker-windows
script:
- '& "C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\Bin\MSBuild.exe" ./src/KDI/KDI.sln /t:Restore /p:AndroidBuildApplicationPackage=true /p:Configuration=Release'
- '& "C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\Bin\MSBuild.exe" /p:Configuration=Release /t:SignAndroidPackage /property:SolutionDir="C:\builds\gitlab\HMI.Framework\KDI\src\KDI\" /p:AndroidSigningKeyStore="C:\builds\gitlab\HMI.Framework\KDI\distribution\Android\KrohneAndroidKeystore.keystore" .\src\KDI\KDI\KDI.Android\KDI.Android.csproj'
run_bb_tests:
stage: test
only:
- CI_CD
tags:
- docker-windows
script:
- docker-ci/install_and_run_bb_tests.bat "phone_ip" "5555" arg1 arg2 || true
- adb pull /storage/emulated/0/Android/data/myApp/files/Exports/BBT_Exports/BBTests_CI C:\test_results
artifacts:
paths:
- c:\test_results\BBTests_CI #expire in 1 month by default
如果我使用以下方式启动此图像:docker 运行 -it myImage powershell 一切正常,但如果我 运行 它 docker 运行 -it myImage powershell -NoProfile,msbuild 在构建 xamarin 应用程序的某个步骤失败
- How can I prevent Gitlab from adding -NoProfile when creating the docker container?
显然你不能...还 but there is a feature request in place
- What's the difference between using powershell with -NoProfile and without it?
PowerShell 配置文件只是一个包含特定用户自定义功能等内容的文件。例如,如果我的 PowerShell 配置文件中包含 Function Banana(){Write-Host "Awesome"}
,例如 $Home[My]Documents\PowerShell\Profile.ps1。每当我打开 PowerShell 时,它都会自动加载该功能。所以我可以打开 PowerShell,键入 banana
并将字符串 Awesome
写入标准输出。如果我用 -NoProfile 启动 powershell,然后输入 banana
,我会得到 CommandNotFoundException
。
source
- Is there any way if I run powershell -NoProfile to somehow load/run the default profile and to revert the effect of setting -NoProfile flag?
也许吧。我只是说也许是因为我没有亲自测试过它,但理论上它应该有效。如果配置文件在容器中,您所要做的就是点源它。
. "C:\path\to\powershell\profile.ps1"
dot sourcing .ps1 文件将 运行 当前范围内的任何内容,其中包括加载函数(如果存在)。 dot source docs
我在 Gitlab 上的专业知识有限,但由于我对 Windows 容器、PowerShell 的整体经验以及 PowerShell 配置文件的性质,我怀疑配置文件是这个问题的根本原因,但我没有足够的 information/evidence 来明确地说。希望这在某种程度上有所帮助!