【发布时间】:2019-12-13 21:37:53
【问题描述】:
我正在尝试将系统变量从 azure devops 传递给 python 脚本。这是我目前在 Yaml 文件中的内容:
- script: pytest test/test_pipeline.py
--$(global_variable)
--junitxml=$(Build.StagingDirectory)/test_pipeline-results.xml
displayName: 'Testing Pipeline'
condition: always()
我在脚本中需要的变量是$(global_variable)。该变量包含一个值$(Build.SourcesDirectory)。它是全局变量。当我运行作业时,我收到一条错误消息"unrecognised arguments"。
解决此问题的任何帮助都会有所帮助。
谢谢!
编辑:
完整的日志:
`##[section]Starting: Testing Pipeline
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.151.2
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
pytest test/test_pipeline.py --my_param="/home/vsts/work/1/s" --junitxml=/home/vsts/work/1/a/test_pipeline-results.xml
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/64fb4a65-90de-42d5-bfb3-58cc8aa174e3.sh
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --my_param=/home/vsts/work/1/s
inifile: None
rootdir: /home/vsts/work/1/s
##[error]Bash exited with code '4'.
##[section]Finishing: Testing Pipeline`
【问题讨论】:
-
您可以尝试使用 Python 脚本任务。在
Arguments中,您可以在其中传递变量。 -
我也尝试过。类似这样的东西:-任务:PublishTestResults@2 条件:always() displayName:“测试用例的测试管道”输入:参数:$(global_variable)testResultsFiles:$ (Build.StagingDirectory)/test_pipeline-results.xml testRunTitle: 测试管道
-
你在哪里定义
global_variable? -
@ShaykiAbramczyk 一开始。为了确定,我也附和了这个值。它确实存储了我想要的东西。
-
您介意更新问题中的完整日志吗?
标签: python-3.x azure azure-devops yaml