是否可以读取或将 Azure Pipelines 脚本返回的数据保存在变量中?

Ton*_*pez 5 yaml azure azure-devops azure-pipelines

我有一个 Azure Devops Pipeline,它有一个这样的任务脚本:

steps:
  - script: python settings.py
Run Code Online (Sandbox Code Playgroud)

这个脚本“返回”(内部生成一个打印('...'))一个我想在管道中保存以供以后使用的值,但我找不到办法做到这一点。

我试过日志记录,但我认为这是不可能的:

steps:
  - script: echo '##vso[task.setvariable variable=version]'${python settings.py}
Run Code Online (Sandbox Code Playgroud)

是否有可能以任何方式或没有人能够做到这一点?

谢谢。

小智 10

您可以在 python 脚本中添加此代码以保存该值以供以后在管道中使用。想法是将其输出到控制台,VSTS 会自动将其保存在变量 - 版本下。

print('##vso[task.setvariable variable=version;]%s' % (version))
Run Code Online (Sandbox Code Playgroud)