conditional set of a variable based on another ENV variable

In a given Dockerfile, I want to set a variable based on content of another ENV variable (which is injected into the container beforehand, or defined within the Dockerfile)

I’m looking at something like this

FROM centos:7
ENV ENABLE_REMOTE_DEBUG "true"

ENV DEBUG_FLAG=""
RUN if [ "$ENABLE_REMOTE_DEBUG" = "true" ] ; then echo "set debug flag" ;export DEBUG_FLAG="some_flags"; else echo "remote debug not set" ; fi

RUN echo debug flags: ${DEBUG_FLAG}

## Use the debug flag in the Entrypoint : java jar ${DEBUG_FLAG} ...

the problem with this Dockerfile is $DEBUG_FLAG is not properly set (or is not being used in the next line? ) … since output is empty:

debug flags:

What am I missing here? (I prefer not to call external bash script)

Source: StackOverflow