2

According to this very old question you can use Bamboo variables in a batch script like %bamboo_buildNumber%, but it doesn't work for me, I just get an empty string. I also tried %bamboo.buildNumber% with the same result. The script is not in-line and is used by a Dockerfile. Does that have an influence on this? Or did something change since the above question was asked?

In the script I have a line

innosetup-compiler MySetup.iss "--DVERSION=%major%.%minor%" "--DPATCH=%bamboo_buildNumber%"

And in my Dockerfile I write

RUN ./MyScript.bat

Update:

So I think whats happening is that because the batch-script is run from the Dockerfile it is also run inside a container and doesn't have access to the Bamboo environment variables because of this. I tried passing the variable in question through the Dockerfile into the script, but it hasn't worked as of yet.

TigersEye120
  • 664
  • 1
  • 9
  • 28
  • could you add some example where you add the variable ? – LinPy Sep 11 '19 at 10:17
  • @LinPy added some code – TigersEye120 Sep 11 '19 at 11:15
  • How are you calling the `docker build` command? – Stefano Sep 11 '19 at 12:29
  • @Stefano I'm using the Bamboo Docker-Task, which as far as I can see is nothing more then a fancy UI which assembles the commad for you. Or do you mean something different? – TigersEye120 Sep 11 '19 at 12:38
  • I'm sorry... I meant if you tried to replicate the same behavior locally to verify if it's an issue with the bamboo or something else in the docker image generation. I left the important part of the thinking on the keyboard :P – Stefano Sep 11 '19 at 12:40
  • So you mean my exact docker build command? That would be `docker build --no-cache=true --force-rm=true --tag=myimage .` – TigersEye120 Sep 11 '19 at 12:47

2 Answers2

1

I believe that this has changed in newer versions of Bamboo. The preferred syntax now is to use ${bamboo.buildNumber} when passing variables to a build script. I even use that approach in my old /bin/sh cmd.exe scripts. You'll know you've got it working when you see the following in the logs:

Substituting variable: ${bamboo.buildNumber} with xxxx

Once you verify that the above variable substitution is working, you can then troubleshoot how that variable is getting (or not getting) into your Docker scripts.

For more information on the major minor build numbers check out this page. You may need to call it slightly differently if it is a custom variable.

Wesley Rolnick
  • 871
  • 4
  • 11
  • I checked and the only variable that gets substituted is bamboo.working.directory. Then, before every new task, it says "using extra environment variables: [...]bamboo_buildNumber=42[...]". But when I write ${bamboo_buildNumber} in the script, it says "unknown constant". – TigersEye120 Sep 12 '19 at 06:24
  • @TigersEye120: That's because it should be a . (period) not an _ (underscore). So ${bamboo.buildNumber} – Wesley Rolnick Sep 12 '19 at 11:21
  • But it says "bomboo_buildNumber" in the log. And if I replace the underscore with a point it also says "unknown constant". – TigersEye120 Sep 12 '19 at 11:36
1

if we are using the script body in bamboo script task then ${bamboo.buildNumber} will work without any issue but if we need to access in bat file or a ps1 file then it is required to access in the below syntax

%bamboo_buildNumber% In a .bat file use

$Env:bamboo_buildNumber in a Powershell file

Sughosh R
  • 11
  • 2