davjfish
davjfish

Reputation: 345

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

I am trying to run a simple bash script using a yaml pipeline through MS DevOps. I want to be using Python version 3.8. When connecting to the self-hosted agent via SSH, I am able to run the script specified in the yaml file without any problems. However, when I run the script through the pipeline, it fails because for some reason the python alias is referring to Python 2.7.17.

I tried setting the following alias in both the .bashrc for the agentsvc user as well as in the bash.bashrc file: alias python='python3.8'.

I realize I can change python to python3.8 in my script however I do not want to do this. Does anybody have any ideas why the alias is not working in the pipeline environment and what I can do to fix this?

Here is a sample of the yaml pipeline that I am trying to run:

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.'

Upvotes: 1

Views: 3418

Answers (1)

Vito Liu
Vito Liu

Reputation: 8298

As a workaround, we can try below cmd to use Python3.x version

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

Result:

enter image description here

Also, we can use the task Use Python version to specify python version. You can refer to this doc to configure your self-hosted agent to use this task.

Result:

enter image description here

Upvotes: 1

Related Questions