[英]Install Python to Self-hosted Windows build agent
我已經安裝了 Windows 代理,我需要能夠運行 Python 腳本。 我知道我需要安裝 Python,但我不知道如何安裝。
我將標准安裝中的 Python 文件添加到
$AGENT_TOOLSDIRECTORY/
Python/
3.8.2/
x64/
{tool files}
x64.complete
重新啟動代理,但現在怎么辦? 如何把它放到 Capabilities 中? 我缺少什么?
編輯:我需要運行這個 YAML 任務
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
addToPath: true
- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
displayName: 'Install dependencies'
- task: BatchScript@1
displayName: 'Run script make.bat'
inputs:
filename: make.bat
arguments: html
我已經在Windows 10筆記本電腦上設置了一個自托管代理(我有管理員訪問權限),並且我正在運行Azure DevOps Express 2020 。
我根據下載和配置代理中的說明找到、下載並安裝了一個代理。 我使用了vsts-agent-win-x64-2.170.1.zip
並將其設置為作為服務運行,(我猜任何手動運行它的人都需要仔細檢查它是否在放映時運行)。 我還在powershell 中以管理員身份運行安裝命令!
要安裝 Python 版本,我需要從Python.org的ftp 站點下載適當的安裝程序,例如。 對於 3.7.9,我使用了python-3.7.9-amd64.exe
。 然后我從沒有 UI的命令行(以管理員身份運行 CMD)運行它: python-3.7.9-amd64.exe /quiet InstallAllUsers=0 TargetDir=$AGENT_TOOLSDIRECTORY\\Python\\3.7.9\\x64 Include_launcher=0
(其他選項用於安裝在python 文檔中可用)
一旦完成,(和它在后台運行,從而將需要更長的時間比最初的命令),你需要創建一個空的{platform}.complete
文件(如描述在這里),於我而言,這是x64.complete
。
這然后奏效了! 我確實為第一個版本重新啟動了服務器,但是我已經添加了其他 python 版本,因為不需要。 我的管道任務很簡單:
steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(python.version)'
inputs:
versionSpec: '$(python.version)'
(使用變量python.version
將我們設置為版本列表3.7.9, 3.8.8
)
對我來說,一個關鍵要素是文件結構,其中文檔說{tool files}
這意味着 python.exe 文件和其他常見目錄,例如 Lib 和 Scripts。 我最初將它們安裝在一個不起作用的子目錄中。 所以它應該是這樣的:
$AGENT_TOOLSDIRECTORY/
Python/
3.7.9/
x64/
Doc/
Lib/
Scripts/
python.exe
...etc...
x64.complete
老實說,我感到很欣慰,因為這沒有太多麻煩。 我放棄了讓 Artifacts 在本地工作的嘗試。 根據我有限的經驗,所有這些在雲版本上都更容易、更好。 然而,還沒有說服我的雇主采取這一飛躍......
對於這個問題,為了使用安裝在本地機器上的 python 版本。 您需要在 cmd 任務中指向python.exe
物理路徑。 或者在powershell任務中手動添加python.exe
路徑到環境變量路徑。 例如:
要在 powershell 任務中使用本地 python:
$env:Path += ";c:\{local path to}\Python\Python38\; c:\{local path to}\Python\Python38\Scripts\"
python -V
在 CMD 任務中使用 python:
c:\{local path to}\Python\Python38\python.exe -V
c:\{local path to}\Python\Python38\Scripts\pip.exe install
所以,我想用私有代理運行 python 腳本,只要確保 python 安裝在本地,然后指向 python.exe 路徑。 具體可以參考這個案例。
在能夠使用 vs2017-win2016 代理在我的管道上執行 python 之前,我添加了這 4 個任務:
使用 Python 3.x
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.x'
使用 Pip 身份驗證
steps:
- task: PipAuthenticate@1
displayName: 'Pip Authenticate'
使用命令行任務
steps:
- script: |
python -m pip install --upgrade pip setuptools wheel
failOnStderr: true
displayName: 'install pip for setup of python framework'
使用命令行任務
steps:
- script: 'pip install -r _python-test-harness/requirements.txt'
failOnStderr: true
displayName: 'install python framework project''s specific requirements'
希望有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.