Reputation: 111
I am new to CI and CD world. I am using VSTS pipelines to automate my build and release processs. This question is about the Release Pipeline. My deploy my build drop to a AWS VM. I created a Deployment group and ran the script in the VM to generate a deployment Agent on the AWS VM. This works well and I am able to deploy successfully. I would like to run few automation scripts in python after successful deployment. I tried using Python Script Task. One of the settings is Python Interpretor. the help information says: "Absolute path to the Python interpreter to use. If not specified, the task will use the interpreter in PATH. Run the Use Python Version task to add a version of Python to PATH."
So, I tried to use Python Version Task and specified the version of python I ususally run my scripts with. The prerequisites for the task mention "A Microsoft-hosted agent with side-by-side versions of Python installed, or a self-hosted agent with Agent.ToolsDirectory configured (see Q&A)." reference to Python Version task documentation
I am not sure how and where to set Agent.ToolsDirectory or how to use Microsoft Hosted agent on a release pipeline deploying to AWS VM. I could not find any step by step examples for this. Can anyone help me with clear steps how to run python scripts in my scenario?
Upvotes: 0
Views: 1579
Reputation: 72191
the easiest way of doing this is just doing something like in your yaml definition:
- script: python xxx
this will run python and pass arguments to it, you can use python2 or python3 (default version installed on the hosted agent). another way of achieving this (more reliable) is using container inside hosted agent. this way you can explicitly specify python version and guarantee you are getting what you specified. example:
resources: containers: - container: my_container # can be anything image: python:3.6-jessie # just an example
jobs: - job: job_name container: my_container # has to be the container name from resources pool: vmImage: 'Ubuntu-16.04' steps: - checkout: self fetchDepth: 1 clean: true - script: python xxx
this will start the python:3.6-jessie
container, mount your code inside the container and run the python command in the root of the repo. Reading:
https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azdevops&tabs=schema&viewFallbackFrom=vsts#job
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/container-phases?view=azdevops&tabs=yaml&viewFallbackFrom=vsts
in case you are using your own agent - just install python on it and make sure its in the path, so it should work when you just type python
in the console (you'd have to use script task in this case). if you want to use python task, follow these articles:
https://github.com/Microsoft/azure-pipelines-tool-lib/blob/master/docs/overview.md#tool-cache
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/use-python-version?view=azdevops
Upvotes: 0