The first step is trying to read the version code from app/build.gradle file and save it as an envman variable. It is a bash script and looks like this
The second one just prints the newly saved variable.
- activate-ssh-key@4.0.2: {}
- git-clone@4.0.11: {}
- script@1.1.5:
title: Get current version code
inputs:
- content: |
#!/bin/bash
set -ex
POR="$(grep -o "versionCode\s\+\d\+" app/build.gradle | awk '{ print $2 }')"
echo "$POR" | envman add --key CURRENT_VERSION_CODE
- script@1.1.5:
title: Print version code
inputs:
- content: |
#!/bin/bash
set -ex
echo "VERSION CODE IS: $CURRENT_VERSION_CODE"
description: test something
My question is why am I getting empty value in the second step? What am I doing wrong?
Did you check the build log of the Get current version code step? Is the right version number in there? As you used set -ex it should be printed in the logs if the grep command you used results in a non empty value.
The envman command looks good, probably it could be a bit easier this way - it’s easier to debug as well: envman add --key CURRENT_VERSION_CODE --value "$POR"
But the echo | version should work as well of course. In any case the Get current version code step’s build log should include the value of POR, which is the result of your grep command. I suspect that results in an empty value.
thank you for you answer. You are right, the value is empty but it shouldn’t be. I created a Bitrise step test on my computer locally and tested the same workflow and it works perfectly. I put the same app/build.gradle in _tmp folder. But when running it on the cloud it doesn’t work.
I’ve just figured it out why was failing on Bitrise and not locally. It is because /d is not accepted and [0-9] is. Why is that, I am not sure. I think it depends on which operating system runs. Mine is macOS, on Bitrise was Ubuntu. This link helped me solve this problem.
Glad to hear you found the solution - indeed, although command line tools like grep are similar on Linux and macOS there can be differences, the one you found it is indeed one of those. [0-9] of course should work on both