在最初的一些問題之后,我終于能夠在我的個人筆記本電腦上設定一個自托管的 GitLab Runner。
我現在正在研究這個跑步者是如何作業的,以及我如何根據我的需要調整它的環境。我修改了 YML 檔案以運行一個簡單的命令來回顯PATH環境變數:
stages: # List of stages for jobs, and their order of execution
- run
deploy-job:
stage: run
script:
- echo $env:path.split(";")
當我提交并將其推送到 GitLab 時,管道顯示以下環境:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\Users\921479\AppData\Local\Programs\Python\Python39\Scripts\
C:\Users\921479\AppData\Local\Programs\Python\Python39\
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Windows\System32\OpenSSH\
C:\ProgramData\chocolatey\bin
C:\Users\921479\AppData\Local\SumatraPDF
C:\texlive\2021\bin\win32
C:\Program Files (x86)\PDFtk Server\bin\
C:\Program Files (x86)\Lua\5.1
C:\Program Files (x86)\Lua\5.1\clibs
C:\Program Files\Inkscape\bin
C:\Program Files\dotnet\
C:\Program Files\WindowsPowerShell\Scripts
C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\
C:\Program Files (x86)\dotnet\
C:\Program Files (x86)\glab
C:\Program Files\Git\cmd
C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps
C:\Program Files\Oracle\VirtualBox
C:\Program Files (x86)\Oracle\VirtualBox
然后我從運行主機(即我的本地機器)上的常規 powershell 終端運行完全相同的命令,并得到以下內容:
C:\Users\921479\Miniconda3\envs\temp
C:\Users\921479\Miniconda3\envs\temp\Library\mingw-w64\bin
C:\Users\921479\Miniconda3\envs\temp\Library\usr\bin
C:\Users\921479\Miniconda3\envs\temp\Library\bin
C:\Users\921479\Miniconda3\envs\temp\Scripts
C:\Users\921479\Miniconda3\envs\temp\bin
C:\Users\921479\Miniconda3\condabin
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\Users\921479\AppData\Local\Programs\Python\Python39\Scripts
C:\Users\921479\AppData\Local\Programs\Python\Python39
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0
C:\Windows\System32\OpenSSH
C:\ProgramData\chocolatey\bin
C:\Users\921479\AppData\Local\SumatraPDF
C:\texlive\2021\bin\win32
C:\Program Files (x86)\PDFtk Server\bin
C:\Program Files (x86)\Lua\5.1
C:\Program Files (x86)\Lua\5.1\clibs
C:\Program Files\Inkscape\bin
C:\Program Files\dotnet
C:\Program Files\WindowsPowerShell\Scripts
C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit
C:\Program Files (x86)\dotnet
C:\Program Files (x86)\glab
C:\Program Files\Git\cmd
C:\Users\921479\AppData\Local\Microsoft\WindowsApps
C:\Users\921479\.dotnet\tools
C:\Program Files\Tracker Software\PDF Editor
C:\context\tex\texmf-win64\bin
C:\Program Files (x86)\Symantec\Symantec Endpoint Protection
C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64
C:\Users\921479\handle
C:\Program Files\Google\Chrome\Application
C:\Users\921479\AppData\Local\Pandoc
我有點驚訝路徑不同,考慮到我的跑步者是我的本地機器,在config.toml.
Why does PATH in the Runner and PATH from a regular Powershell environment have different contents?
uj5u.com熱心網友回復:
環境變數可能不同的原因有幾個。主要:
- 跑步者正在使用的用戶帳戶
- 您在本地使用的 powershell 組態檔(跑步者不會使用)
- 在運行程式的 config.toml 中對環境變數所做的任何更改
- 通過 CI/CD 變數更改/添加環境變數。
用戶帳號
有效的PATH是系統環境變數和用戶環境變數的組合。為了讓您的運行器反映您在運行 powershell 時在本地看到的相同環境變數,您必須使用相同的用戶帳戶,否則您看到的用戶環境變數可能會丟失/因用戶帳戶而異。
修復可能由用戶引起的差異的一種方法是更改?? gitlab 服務使用的用戶
要更改 GitLab 運行程式使用的用戶,請轉到服務-> gitlab-runner ->(右鍵單擊)屬性->登錄選項卡并選擇運行程式應使用的帳戶。
或者,在安裝 runner 時指定:
.\gitlab-runner.exe install --user ENTER-YOUR-USERNAME --password ENTER-YOUR-PASSWORD
但是,在您的情況下,您似乎使用相同的用戶(C:\Users\921479\在提供的兩個示例中都存在)。因此,這可能不是您的案例中的具體問題(但我在這里提到它是為了其他遇到問題的人的利益)。
Powershell 組態檔
您的差異可能是使用了powershell 組態檔(未)的結果。Powershell 組態檔可以更改環境變數,例如PATH.
許多程式,包括 Anaconda 的conda init powershell使用 powershell 組態檔來實作PATH更改。但是,當為作業運行 powershell 命令時,用于 powershell 的 GitLab Runner shell 執行程式會傳遞-NoProfile引數,這意味著任何此類組態檔更改都不會出現在 GitLab 作業中,即使使用了相同的正確用戶帳戶。目前,無法覆寫此行為,但存在針對它的功能請求。
要解決此問題,您可以執行以下任一操作:
- 將這些
PATH/environment 變數添加到用戶環境變數(系統 - > 環境變數) - 將
PATH/環境變數添加到系統 - 使跑步者的必要的環境變化
environment的關鍵config.toml。請參閱高級配置。 - 添加變數作為CI/CD variables。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/399965.html
標籤:powershell environment-variables gitlab-ci gitlab-ci-runner
下一篇:傳遞用戶引數并回退到默認值
