相关疑难解决方法(0)

如何将命令输出设置为批处理文件中的变量

是否可以将批处理文件的语句输出设置为变量,例如:

findstr testing > %VARIABLE%

echo %VARIABLE%
Run Code Online (Sandbox Code Playgroud)

windows batch-file

207
推荐指数
7
解决办法
41万
查看次数

使用 AzureCLI@2 的输出作为 Azure DevOps Pipeline 中的变量

我的 git 项目根目录中有一个 azure-pipelines.yml 文件。在此文件中,我想在下一个任务中使用一个任务的输出作为变量。我的任务

- task: AzureCLI@2
            displayName: 'List info on read policy in DEV'
            name: myOutput
            inputs:
              azureSubscription: mySub
              scriptType: ps
              scriptLocation: inlineScript
              inlineScript: az servicebus topic authorization-rule keys list --resource-group myRG --namespace-name mySB --topic-name myTopic --name Listen
Run Code Online (Sandbox Code Playgroud)

在 powershell 中运行此 az 命令时,我得到以下回报:

{
  "aliasPrimaryConnectionString": null,
  "aliasSecondaryConnectionString": null,
  "keyName": "Listen",
  "primaryConnectionString": "Endpoint=sb://someKey",
  "primaryKey": "somePrimaryKey",
  "secondaryConnectionString": "Endpoint=sb://another key",
  "secondaryKey": "someSecondaryKey"
}
Run Code Online (Sandbox Code Playgroud)

我也在管道的日志中得到了这个输出。根据文档,我确实希望能够在下一步中使用它。例如:

- script: echo $(myOutput.primaryConnectionString)
Run Code Online (Sandbox Code Playgroud)

日志给我的不是获取 PrimaryConnectionString 的值,而是:

Starting: CmdLine
==============================================================================
Task         : Command line
Description …
Run Code Online (Sandbox Code Playgroud)

azure azure-devops

7
推荐指数
2
解决办法
9722
查看次数

标签 统计

azure ×1

azure-devops ×1

batch-file ×1

windows ×1