You're right, I don't really understand your point. You want to get rid of the intermediate images after the build has complete. And I am saying you can do that with ENV and LABEL. You do not need to implement your own parser.
A LABEL instruction is not going to interfere with your build process. The label is purely metadata that the docker daemon uses. Nothing 'inside' the image itself gets changed. I'd advise you to read the documentation more closely, as this is precisely what the LABEL instructure is made for. If you find yourself implement your own Dockerfile parser, you are over-complicating things.
Yes you'd need to modify the Dockerfile to include the ENV and LABEL instructions. I am not sure why this is a complex procedure, would you mind clarifying?
@AndrewSavinykh Perhaps you can set a unique build ID as an environment variable inside your Jenkins build, add it to the image using ENV, and use environment replacement to use that build ID as the label value