Azure 管道命令行代理作业似乎忽略了 python 环境激活后的命令?
Azure pipeline command line agent job seems to ignore the commands following the python environment activation?
我正在使用foll。 Azure 管道命令行代理作业中的代码。但是 Venv_Project\scripts\activate
之后的命令不会显示在输出中。可能是什么问题?
ECHO START
SET var=%cd%
ECHO %var%
python -m venv Venv_Project
SET var=%cd%
ECHO %var%
ECHO Venv created and now activating
Venv_Project\scripts\activate
SET var=%cd%
ECHO %var%
ECHO END
Azure pipeline command line agent job seems to ignore the commands following the python environment activation?
我可以在旁边重现这个问题。为了进一步验证命令是否执行,或者执行了但没有显示在输出中。
我创建了一个简单的python脚本来创建.txt
文件,所以我们可以通过验证.txt
文件的存在来验证命令是否被执行:
file = open('D:/a/1/s/Test.txt', 'w');
file.write('hello, \n world!')
当我在没有激活 python 环境的情况下使用私人代理构建命令行任务时,它成功创建了 .txt
文件。但是如果我激活 python 环境激活,它不会创建那个文件。
因此,这进一步确定该命令不是使用Azure devops 执行的。但是我没有办法进一步弄清楚Azure devops在python虚拟环境中不执行命令的原因。
要解决此问题,建议您在开发者社区报告此问题:
https://developercommunity.visualstudio.com/spaces/21/index.html
这是我们解决产品问题的主要论坛。感谢您帮助我们构建更好的 Azure DevOps。
希望对您有所帮助。
将 Venv_Project\scripts\activate
替换为 call Venv_Project\scripts\activate
Running batch and .CMD files
Azure Pipelines puts your inline script
contents into a temporary batch file (.cmd) in order to run it. When
you want to run a batch file from another batch file in Windows CMD,
you must use the call command, otherwise the first batch file is
terminated. This will result in Azure Pipelines running your intended
script up until the first batch file, then running the batch file,
then ending the step. Additional lines in the first script wouldn't be
run. You should always prepend call before executing a batch file in
an Azure Pipelines script step.
Important
You may not realize you're running a batch file. For example, npm on
Windows, along with any tools that you install using npm install -g,
are actually batch files. Always use call npm to run NPM
commands in a Command Line task on Windows.
我正在使用foll。 Azure 管道命令行代理作业中的代码。但是 Venv_Project\scripts\activate
之后的命令不会显示在输出中。可能是什么问题?
ECHO START
SET var=%cd%
ECHO %var%
python -m venv Venv_Project
SET var=%cd%
ECHO %var%
ECHO Venv created and now activating
Venv_Project\scripts\activate
SET var=%cd%
ECHO %var%
ECHO END
Azure pipeline command line agent job seems to ignore the commands following the python environment activation?
我可以在旁边重现这个问题。为了进一步验证命令是否执行,或者执行了但没有显示在输出中。
我创建了一个简单的python脚本来创建.txt
文件,所以我们可以通过验证.txt
文件的存在来验证命令是否被执行:
file = open('D:/a/1/s/Test.txt', 'w');
file.write('hello, \n world!')
当我在没有激活 python 环境的情况下使用私人代理构建命令行任务时,它成功创建了 .txt
文件。但是如果我激活 python 环境激活,它不会创建那个文件。
因此,这进一步确定该命令不是使用Azure devops 执行的。但是我没有办法进一步弄清楚Azure devops在python虚拟环境中不执行命令的原因。
要解决此问题,建议您在开发者社区报告此问题:
https://developercommunity.visualstudio.com/spaces/21/index.html
这是我们解决产品问题的主要论坛。感谢您帮助我们构建更好的 Azure DevOps。
希望对您有所帮助。
将 Venv_Project\scripts\activate
替换为 call Venv_Project\scripts\activate
Running batch and .CMD files
Azure Pipelines puts your inline script contents into a temporary batch file (.cmd) in order to run it. When you want to run a batch file from another batch file in Windows CMD, you must use the call command, otherwise the first batch file is terminated. This will result in Azure Pipelines running your intended script up until the first batch file, then running the batch file, then ending the step. Additional lines in the first script wouldn't be run. You should always prepend call before executing a batch file in an Azure Pipelines script step.
Important
You may not realize you're running a batch file. For example, npm on Windows, along with any tools that you install using npm install -g, are actually batch files. Always use call npm to run NPM commands in a Command Line task on Windows.