[GitHub Action] Get gradle package version

For executing pipeline, it is common to get package version. One of the patrice is mark the package version in package info file.

In this example, it will use Gradle as example to show how to get package version and call it in in other steps.

Steps

  1. Update GitHub Action.
    Add steps below in GiutHub action.

    - name: Read package version
      id: get-version
      run: |
        version=$(grep -oP "version\s*=\s*'[^']+'" build.gradle | grep -oP "[^']*" | tr -d '\n' | tr -d ' ' | tr -d 'version=')
        echo "::set-output name=version::${version}"
    
    - name: Print package version
      run: |
        echo "Testing current version."
        echo "Package version is ${{ steps.get-version.outputs.version }}"
  2. Check result
    Execute the pipeline to check result, expect version in build.gradle mentioned will shown.
About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.