如何将 azure cli 命令的输出添加到 github 操作

How do I add output of azure cli command to github actions

我有一个 github 操作,我在其中登录到我的 azure 帐户,我想将 azure cli 命令的输出添加到 github 操作变量。我该怎么做?

这是我的github动作片

jobs:
    StagingBuildAndDeploy:
     name: Build and Deploy
     runs-on: ubuntu-latest
     steps:
     - uses: actions/checkout@master
     - name: 'Login via Azure CLI'
       uses: azure/login@v1
       with:
         creds: ${{ secrets.AZURE_CREDENTIALS }

现在我想将此命令的输出添加到变量

az acr repository show-tags --name acrname --repository reponame --orderby time_desc --top 1 

此命令会为我获取 acr 中的最新图像。如何将该图像名称添加到 github 动作变量

我试过这样做

- name: Read image_name
       id: getimagename
       run: echo "::set-output name=image_name::$(az acr repository show-tags --name acrname --repository reponame --orderby time_desc --top 1)"

然后我尝试通过 ${{ steps.getimagename.outputs.image_name }}

访问它

这是我在为变量赋值时得到的输出结果

Run h=$(az acr repository show-tags --name acrname --repository *** --orderby time_desc --top 1)
  "tag132"
]

这是我打印变量时得到的结果

Run echo "["
[

我用这个做了测试:

jobs:
  test-job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout this repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 2

      - name: Test1
        id: test1
        run: |
          h=$(az --version)

          echo "::set-output name=h::$h"

      - name: Test2
        run: |
          echo "${{ steps.test1.outputs.h }}"

并且有效:

查询下方

az acr repository show-tags --name acrname --repository *** --orderby time_desc --top 1

产生如下输出:

[
  "SomeValue"
]

但是如果你加上-o tsv

az acr repository show-tags --name acrname --repository *** --orderby time_desc --top 1 -o tsv

那么你将得到值:

SomeValue