3

I'm trying to update the path variable in Linux VM in GitHub CI.

What I'm trying are:

  • export PATH="${PATH}:$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools/bin"
  • export PATH=$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools/bin:$PATH

But nothing seems to working, as when I'm trying to echo, it doesn't return me what I was expecting. What it lists is:

/home/runner/.local/bin
/opt/pipx_bin
/home/runner/.cargo/bin
/home/runner/.config/composer/vendor/bin
/usr/local/.ghcup/bin
/home/runner/.dotnet/tools
/snap/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin

It should have contained (or at least something like this):

/usr/lib/android-sdk/cmdline-tools/cmdline-tools/bin

Full job details: https://github.com/maifeeulasad/unmukto/actions/runs/3590283087/jobs/6043518013

2
  • why not installing that with the related action, like github.com/marketplace/actions/setup-android-sdk-tools Commented Dec 1, 2022 at 11:46
  • 1
    @Matteo thanks Sir, that's a nice alternative... but I'm trying to learn more about 'pipeline', that's why I'm experimenting... and trying to learn... (trial error)* success... maybe... Commented Dec 2, 2022 at 6:53

1 Answer 1

7

It does get added to the $PATH, but you can't use it in subsequent steps because GitHub Actions isolates steps from one another. If you ran sdkmanager --version in the same step that you update the $PATH in, it would work. Use the GitHub Actions syntax for Adding a system path to append to $GITHUB_PATH, which will automatically persist your edit across the rest of steps in the job:

Prepends a directory to the system PATH variable and automatically makes it available to all subsequent actions in the current job; the currently running action cannot access the updated path variable.

An abbreviated version of your build.yml using $GITHUB_PATH:

name: build Android

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: 'Exporting android sdk'    
      run: echo "ANDROID_SDK_ROOT=/usr/lib/android-sdk" >> $GITHUB_ENV
    - name: 'Download and extract android-cli tools'    
      run: |
        curl https://dl.google.com/android/repository/commandlinetools-linux-9123335_latest.zip --output commandlinetools-linux-9123335_latest.zip
        sudo mkdir /usr/lib/android-sdk/cmdline-tools
        sudo unzip -o commandlinetools-linux-9123335_latest.zip -d /usr/lib/android-sdk/cmdline-tools
    - name: 'Exporting android-cli (sdkmanager) ,'    
      run: echo "${{ env.ANDROID_SDK_ROOT }}/cmdline-tools/cmdline-tools/bin" >> $GITHUB_PATH

Also note how instead of exporting ANDROID_SDK_ROOT, it's added to the $GITHUB_ENV and accessed in a subsequent step with ${{ env.ANDROID_SDK_ROOT}}.

Sign up to request clarification or add additional context in comments.

1 Comment

You can use it in subsequent steps of the same job and only there. Apparently, in the documentation, actions = steps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.