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

Time:09-29

I have a github action where I am logging in to my azure account and I want to add output of azure cli command to github action variable. How do I do this?

This is my github action job

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 }

Now I want add output of this command to a variable

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

This command would fetch me the latest image in acr. How do I add that image name to a github action variable

I tried doing this

- 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)"

and then I tried accessing it by this ${{ steps.getimagename.outputs.image_name }}

This is what I was getting as output when I am assigning the value to variable

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

This is what I got when I printed my variable

Run echo "["
[

CodePudding user response:

I made a test with this:

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 }}"

and it works: enter image description here

Below query

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

produces output as follows:

[
  "SomeValue"
]

But if you add -o tsv

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

then you will get just value:

SomeValue
  • Related