* If git repository does not exist on a shared folder path, then clone it, else pull the last code.
* If virtual environment folder (.venv) does not exist on a shared folder path, then create and activate the virtual environment, else activate the current environment.
* Install python packages located in the file requirements.txt
This is my current YAML file to reach the previous steps:
trigger:
- main
pool:
vmImage: 'windows-latest'
name: 'On Premise Windows'
demands: Agent.Name -equals [Agent_name]
variables:
- group: Variable_Group
- name: PAT
value: $[variables.PAT]
steps:
- checkout: self
displayName: 'Checkout Repository'
- powershell: |
$parent_folder = '\\server\my\shared\folder\path'
$target_folder = Join-Path -Path $parent_folder -ChildPath '[project_name]'
$target_folder_exists = Test-Path -Path $target_folder
if ($target_folder_exists) {
cd $target_folder
git pull
} else {
git clone '
https://$(PAT)@dev.azure.com/my/git/project' $parent_folder
}
enabled: True
displayName: 'Clone or Pull Git repository'
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
- powershell: |
$parent_folder = '\\server\my\shared\folder\path\[project_name]'
$target_folder = Join-Path -Path $parent_folder -ChildPath '.venv'
&requirements_path = Join-Path -Path $parent_folder -ChildPath 'requirements.txt'
$target_folder_exists = Test-Path -Path $target_folder
if ($target_folder_exists) {
cd &parent_folder
& C:\"Program Files"\Python311\python.exe -m venv .venv
}
pip install -r $requirements_path
displayName: 'Setup Python Environment and Install Dependencies'
The agent I am using is intalled On-Premise server and my shared folder path is located in an Azure VM. I am getting the following error:
========================== Starting Command Output =========================== "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo
-NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". '....'" fatal:
could not create leading directories of
'\server\my\shared\folder\path':
No such file or directory
##[error]PowerShell exited with code '1'. Finishing: Clone or Pull Git repository
It seems the On-premise server must have access to that shared folder path. Therefore, I have the following questions:
* Could On-premise server have access to the shared folder path if I give an user which has access to it? if so, how should I pass the user and password to access that path?. If not, what should be the proper way to achieve it?
* Is powershell a good approach to clone my repository and then to install the python packages? If not, what would be the rigth approach?
0 comments:
Post a Comment
Thanks