The reason the above example does not work is because the custom_labels is a Go string literal. It is not passed through a bash interpreter and therefore does not understand or evaluate bash syntax. As you mentioned you would probably need to modify the dockerfile during a preceding step.
However, with that being said, the docker plugin supports the opencontainers label specification and automatically adds these labels, by default. It works out-of-the-box with no additional configuration needed. You can find the relevant code here: