'Github Actions: output variable is empty
I created an action that publishes my app apk. Now im tying to handle version naming on release, but im stuck bc output variable is empty .
The action.yml is:
name: Android CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
apk:
name: Generate the apk file
runs-on: ubuntu-latest
outputs:
version: ${{ steps.getVersion.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name : Upload APK file
uses: actions/upload-artifact@v1
with:
name: apk
path: app/build/outputs/apk/debug/app-debug.apk
- name: Get app version
id: getVersion
run: |
echo "::set-output name=version::$(./gradlew printVersionName)"
release:
name: Release the apk
needs: apk
runs-on: ubuntu-latest
steps:
- name: Download APK from build
uses: actions/download-artifact@v1
with:
name: apk
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: Release${{ needs.apk.outputs.version }}
release_name: Release ${{ needs.apk.outputs.version }}
- name: Upload Release APK
id: upload_release_asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: apk/app-debug.apk
asset_name: takeThatProduct.apk
asset_content_type: application/zip
The step to get version works well, is defined in my build.gradle:

But when i get the output variable in the release job, its empty:
So, the release gets created buy with no version number. New releases fail because the name already exists.

Solution 1:[1]
Changed my action using this action: apk-info-action
name: Android CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
apk:
name: Generate the apk file
runs-on: ubuntu-latest
outputs:
version: ${{ steps.getVersion.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name : Upload APK file
uses: actions/upload-artifact@v1
with:
name: apk
path: app/build/outputs/apk/debug/app-debug.apk
- name: Get apk info
id: apk-info
uses: hkusu/apk-info-action@v1
with:
apk-path: app/build/outputs/apk/debug/app-debug.apk
- name: Export apk info
id: getVersion
run: |
echo "::set-output name=version::${{ steps.apk-info.outputs.version-name }}"
release:
name: Release the apk
needs: apk
runs-on: ubuntu-latest
steps:
- name: Download APK from build
uses: actions/download-artifact@v1
with:
name: apk
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: Release${{ needs.apk.outputs.version }}
release_name: Release ${{ needs.apk.outputs.version }}
- name: Upload Release APK
id: upload_release_asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: apk/app-debug.apk
asset_name: takeThatProduct.apk
asset_content_type: application/zip
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tyler2P |

