簡體   English   中英

如何在通過 MS DevOps 運行管道時在自托管 (Linux Ubuntu 18.04) 代理上指定 python 版本

[英]How to specify python version on self-hosted (Linux Ubuntu 18.04) agent while running a pipeline through MS DevOps

我正在嘗試通過 MS DevOps 使用 yaml 管道運行一個簡單的 bash 腳本。 我想使用 Python 3.8 版。 當通過 SSH 連接到自托管代理時,我能夠毫無問題地運行 yaml 文件中指定的腳本。 但是,當我通過管道運行腳本時,它失敗了,因為出於某種原因, python別名指的是 Python 2.7.17。

我嘗試在agentsvc用戶的.bashrc以及bash.bashrc文件中設置以下別名: alias python='python3.8'

我意識到我可以在我的腳本中將python3.8 python我不想這樣做。 有沒有人知道為什么別名在管道環境中不起作用以及我可以做些什么來解決這個問題?

這是我嘗試運行的 yaml 管道示例:

pool: myubuntuagent

trigger:
  - master

steps:
  - script: |
      # install pre-requisites
      whoami
      python -V
      python -m pip install -r requirements.txt
    workingDirectory: '$(System.DefaultWorkingDirectory)'
    displayName: 'Install Prerequisites etc. etc. etc.'

作為解決方法,我們可以嘗試使用以下 cmd 來使用 Python3.x 版本

python3 -V
python3 -m pip install -r requirements.txt

結果:

在此處輸入圖像描述

此外,我們可以使用任務Use Python version來指定 python 版本。 您可以參考此文檔來配置您的自托管代理以使用此任務。

結果:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM