【问题标题】:Azure Pipelines Python FileNotFoundError in /home/vsts/work/1//home/vsts/work/1/ 中的 Azure Pipelines Python FileNotFoundError
【发布时间】:2020-11-06 13:35:25
【问题描述】:

我正在尝试在 Python 中设置 Azure Pipeline,并使用以下命令测试单个 .py 脚本:
- script: python Directory/Directory2/script_name.py
我在脚本中有一些日志记录功能,我使用 logging.basicConfig 将日志记录目录设置为:
..Logs/file.log
当我运行 Azure Pipeline 时,我收到以下错误:
FileNotFoundError: [Errno 2] No such file or directory: '/home/vsts/work/1/Logs/file.log'
如何让 Azure Pipelines 写入正确的目录?

我还尝试将我的工作目录设置为:
workingDirectory: Directory/Directory2/

【问题讨论】:

  • 能否请将变量 system.debug 设置为 true,然后与我们分享 Python 示例和完整日志?根据日志,文件路径应该是/home/vsts/work/s/1/Logs/file.log

标签: python azure azure-devops yaml azure-pipelines


【解决方案1】:

问题是您正在尝试写入不存在的文件。因此,要么你将在你的 python 脚本中处理这个,要么在你运行你的 python 脚本之前添加这个步骤:

- bash: |
    mkdir directory
    touch directory/file

【讨论】:

  • 该目录确实存在于我的存储库中。如果文件不存在,Python 日志库应该创建一个文件。它在本地以这种方式工作。该目录确实存在于我的示例目录 Directory/Directory2/Logs 中。我需要它写在那里而不是 /home/vsts/work/1/
猜你喜欢
  • 2019-09-11
  • 2022-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-03
相关资源
最近更新 更多