Multiple paths in a single variable for Cache: Push

Description of the feature request

In Input Variables section under Bitrise.io Cache:Push, you can set multiple paths separated with newlines; But I need to set multiple paths with a variable defined with a script

Use case / for what or how I would use it

Homebrew can use a Brewfile to declare bundles required for a project, but it doesn’t install those bundles in a specific directory, but in /usr/local/Cellar and /usr/local/opt with all other bundles, which means you can’t just cache the whole brew install path, because it’s too big and contains too many unrelated libraries.

So I need to define a variable that contains those paths with shell script, but I’ve tried several ways including define an array variable and a string variable simply contains \n characters between paths, but none of them worked.

Here’s what I’ve tried as a sample:

bundle_paths=""
install_paths=""
cellar_path=$(brew --cellar)
install_path="/usr/local/opt"
bundles=$(brew bundle list)

for bundle in ${bundles[@]}; do
  bundle_paths+=$cellar_path/$bundle$'\n'
  install_paths+=$install_path/$bundle$'\n'
done

envman add --key BREW_BUNDLE_PATHS --value $bundle_paths
envman add --key BREW_INSTALL_PATHS --value $install_paths

And in Cache:Push Input Variables I’ve added $BREW_BUNDLE_PATHS and $BREW_INSTALL_PATHS, but it can only recognize the first path, so if I can define the paths with a single variable it’d be very helpful.

Thanks!

Hi @lovee,

sorry for the late response.

So you can solve this by slightly modifying your bash script:

bundle_paths=""
install_paths=""
cellar_path=$(brew --cellar)
install_path="/usr/local/opt"
bundles=$(brew bundle list)

for bundle in ${bundles[@]}; do
  bundle_paths="${bundle_paths}\n${cellar_path}/${bundle}"
  install_paths="${install_paths}\n${install_path}/${bundle}"
done

bundle_paths="$(echo -e "$bundle_paths")"
install_paths="$(echo -e "$install_paths")"

envman add --key BREW_BUNDLE_PATHS --value "$bundle_paths"
envman add --key BREW_INSTALL_PATHS --value "$install_paths"

for the cache-push make sure, the cache_paths input’s value looks like this in the bitrise.yml:

        - cache_paths: |-
...
            $BREW_BUNDLE_PATHS
            $BREW_INSTALL_PATHS
...
1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.