Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update PATH in GitHub Actions

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

like image 867
Maifee Ul Asad Avatar asked Mar 03 '26 04:03

Maifee Ul Asad


1 Answers

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

like image 116
Ed Kloczko Avatar answered Mar 04 '26 22:03

Ed Kloczko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!