Determining build target settings at build time

I’m trying to use the BUILD_BALENA_MACHINE_NAME parameter in my Dockerfile.template and in my CMakefile.txt:

FROM balenalib/%%BALENA_MACHINE_NAME%%-ubuntu:bionic-build

ENV BUILD_BALENA_MACHINE_NAME=%%BUILD_BALENA_MACHINE_NAME%%

and in CMakeLists.txt

...
    if( $ENV{BUILD_BALENA_MACHINE_NAME} STREQUAL "intel-nuc")
...

but now I’m getting:

git push balena
Enumerating objects: 118, done.
Counting objects: 100% (118/118), done.
Delta compression using up to 4 threads
Compressing objects: 100% (91/91), done.
Writing objects: 100% (91/91), 28.00 KiB | 2.00 MiB/s, done.
Total 91 (delta 72), reused 0 (delta 0)

[Info]         Starting build for rv-camera-rpi3b, user oldmacdonald
[Info]         Dashboard link: https://dashboard.balena-cloud.com/apps/1514854/devices
[Error]        Could not detect project type: Service camera: BUILD_BALENA_MACHINE_NAME is not defined
[Error]        Not deploying release.

remote: error: hook declined to update refs/heads/master
To git.balena-cloud.com:oldmacdonald/rv-camera-rpi3b.git
 ! [remote rejected] master-> master (hook declined)
error: failed to push some refs to 'oldmacdonald@git.balena-cloud.com:oldmacdonald/rv-camera-rpi3b.git'

How did I break my app?

Hi, do you mean BALENA_MACHINE_NAME? https://www.balena.io/docs/learn/develop/dockerfile/#dockerfile-templates

Sorry, misread the text. Looking into it.

I think you should use ARG instead of ENV, because BALENA_MACHINE_NAME is the build variable.

Yes, I should have used “BALENA_MACHINE_NAME” on the right side of the ENV variable definition in my Dockerfile.template:

FROM balenalib/%%BALENA_MACHINE_NAME%%-ubuntu:bionic-build
ENV BUILD_BALENA_MACHINE_NAME=%%BALENA_MACHINE_NAME%%

and the CMakeLists.txt as above. Sorry for the confusion. Now that I look at my question I see the error.