Azure Pipelines - 从 python 脚本文件到管道变量的输出变量
Azure Pipelines - Output variable from python script file to pipeline variable
我已经尝试了来自 Whosebug 的几篇文章和主题,但似乎无处可去。我正在尝试从在 YAML 步骤中调用的 .py 文件中获取一个变量,并在全局范围内设置该变量以供使用。
在我的 .py 文件中 我有
print(f'##vso[task.setvariable variable=AMLPipelineId;isOutput=true]{pipelineId}')
然后在我的 YAML 管道步骤中我有
- task: AzurePowerShell@5
displayName: 'Run AML Pipeline'
inputs:
azureSubscription: '$(azureSubscription)'
ScriptType: 'InlineScript'
name: AmlPipeline
azurePowerShellVersion: 'LatestVersion'
pwsh: true
Inline: |
$username = "$(ARM_CLIENT_ID)"
$password = "$(ARM_CLIENT_SECRET)"
$tenantId = "$(ARM_TENANT_ID)"
python $(Pipeline.Workspace)/AML_Pipeline/build_aml_pipeline.py --wsName $(wsName) --resourceGroup $(ResourceGroupName) --subscriptionId $(subId)
$MLPipelineId = $AmlPipeline.AMLPipelineId
但是这个变量好像是空的。我知道还有其他使用“设置变量”的方法,但这是我最近的尝试,例如 print('##vso[task.setvariable variable=version;]%s' % (version))
- 您不需要
isOutput=true
- 只需要在不同作业或阶段之间引用变量。
- "You cannot use the variable in the step that it is defined." - 将该脚本分为两步:第一步运行您的
.py
文件,第二步使用新定义的变量。
我用了print('##vso[task.setvariable variable=<Variable-in-Pipeline]+<output-variable>')
Variable-in-Pipeline // the given name should be used in Azure Devops pipeline and should be added to pipeline variables as an empty string
我已经尝试了来自 Whosebug 的几篇文章和主题,但似乎无处可去。我正在尝试从在 YAML 步骤中调用的 .py 文件中获取一个变量,并在全局范围内设置该变量以供使用。
在我的 .py 文件中 我有
print(f'##vso[task.setvariable variable=AMLPipelineId;isOutput=true]{pipelineId}')
然后在我的 YAML 管道步骤中我有
- task: AzurePowerShell@5
displayName: 'Run AML Pipeline'
inputs:
azureSubscription: '$(azureSubscription)'
ScriptType: 'InlineScript'
name: AmlPipeline
azurePowerShellVersion: 'LatestVersion'
pwsh: true
Inline: |
$username = "$(ARM_CLIENT_ID)"
$password = "$(ARM_CLIENT_SECRET)"
$tenantId = "$(ARM_TENANT_ID)"
python $(Pipeline.Workspace)/AML_Pipeline/build_aml_pipeline.py --wsName $(wsName) --resourceGroup $(ResourceGroupName) --subscriptionId $(subId)
$MLPipelineId = $AmlPipeline.AMLPipelineId
但是这个变量好像是空的。我知道还有其他使用“设置变量”的方法,但这是我最近的尝试,例如 print('##vso[task.setvariable variable=version;]%s' % (version))
- 您不需要
isOutput=true
- 只需要在不同作业或阶段之间引用变量。 - "You cannot use the variable in the step that it is defined." - 将该脚本分为两步:第一步运行您的
.py
文件,第二步使用新定义的变量。
我用了print('##vso[task.setvariable variable=<Variable-in-Pipeline]+<output-variable>')
Variable-in-Pipeline // the given name should be used in Azure Devops pipeline and should be added to pipeline variables as an empty string