Search code examples
azure-devopsazure-pipelinesazure-pipelines-yaml

Azure pipeline - can't find Python script although it is in the same directory as the yml file


I'm trying to get my pipeline to run a Python script. The script is in the same directory as the yml file, so I think this is the way to do it:

- task: PythonScript@0
  inputs:
    scriptSource: 'filePath'
    scriptPath: '$(System.DefaultWorkingDirectory)/myTestPythonFile.py'

The yml file and the python file are in the same folder

enter image description here

However, upon running the pipeline, I run into the following error: ##[error]ENOENT: no such file or directory

enter image description here

What am I doing wrong?


Solution

  • I can reproduce your error with your yaml.

    enter image description here

    The command git checkout -b DIN_grafana_json_archives --track origin/DIN_grafana_json_archives will create a new local branch DIN_grafana_json_archives and switch to it, it's tracking the remote branch. You can check the link for the command behavior details.

    After the command, the working directory content is from the new branch, not the self branch. And in your new branch, there is no target python file, which will cause the error.

    In addition, to make sure the directory content, you can add bash task to list the files in the working directory before pythonscript task for a check.

    - bash: |
       find . -type f
      displayName: checkout file list
    
    - task: PythonScript@0
    ....