Thanks for your patience.
Env Vars created by the script step are not directly cached, you would need need to use envman , which creates a .envstore file which then can be cached: envman/README.md at master · bitrise-io/envman · GitHub
Unfortunatelly, I did not get the point. I already use envman to store variable:
envman add --key MY_COUNTER --value "$counter"
Should I also configure a push step to cache .envstore file? (I could not locate this file)
Please specify what should I do, so variable is cached and can be reused on next builds?
(I would appreciate if you make modifications to the flow, so MY_COUNTER is saved across builds)
You can only create permanent variables on the website, the values are not getting stored automatically because it’s a modification only happening in the build machine.
If you modify a variable the .envstore file gets created in the your current working directory, so that’s where it can be exported from (GitHub - bitrise-io/envman: Environment variable manager).
Could you tell us a bit more about what you are trying to do with this counter? Perhaps there is a more convenient solution
I am trying to setup flow, so it finishes early if specific folders in project are not modified. In order to do that, I would need to check changes (we use git) for those folder between last build revision and current revision, that means I need to store git revisions for folders after last build and update those revisions after each build.
That is why I need some env variables that will be stored across builds. If you know a better way, how to achieve “no modification (for specific folders of a project) - no build” behaviour please share it.
You could try using Selective Builds for that same effect, as this feature was designed with a similar idea in mind: Selective builds | Bitrise DevCenter
It looks like what I need. The only problem selective builds only work for gitHub repository. Unfortunately we do not use a github.
So it seems like I am tight to develop a manual solution.
Could you please provide a code snippet to save envman file across builds?
Short answer -> it is better to use a cache files (along with cache pull and cache push steps) to store such variables and then load them to envman, so they are available at each build step.
Long answer -> It seamed to me that envman should not only carry variables between workflow steps, but also save and restore variables between builds. It seemed like a better way rather then store variables in cache files.
I could not get a clear answer from @Roland-Bak (after giving full access to a workflow & waisting 2 weeks to discus the problem), but I have found a thread Save state between build where similar problem was described and offered solution was to keep variable in a cache file.
I still spent some time trying to save and restore envman variables file, but it turns out to be not a trivial task.
First I tried to init envman (envman init) to a working directory but that implied a restriction to add --path paramet to every envman command.
Then I tried to update ENVMAN_ENVSTORE_PATH variable and set it to a cached file and that worked, I did not have to add --path to every envman command, but I had to set this variable to every script step.
My last attempt was to push cache file to ENVMAN_ENVSTORE_PATH and copy it back to cache after workflow is completed. But it turned out that ENVMAN_ENVSTORE_PATH file was empty on the very last script step (probably envman clears it`s cache file on beginning or on the end of each step).
So I gave up and applied solution with keeping value in a file