passing arguments to docker

I am trying to pass an argument to docker. For that, I use build-arg in my docker build command.

echo "[INFO] Hadoop version is ${HDP_VERSION}"
docker build --no-cache=true --squash 
--build-arg HDP_VERSION=${HDP_VERSION} 

This is my docker

ARG HDP_VERSION
FROM host:5000/runner-hadoop:${HDP_VERSION}
RUN echo "HDP_VERSION="${HDP_VERSION}
COPY oozie/${HDP_VERSION} ${PATH_UNIX_PROJECT}

The first and second row execute without failing, but after that, I see that HDP_VERSION is actually empty. So at step 4, the wrong directory is taken.

enter image description here

Why is that and how do you correct it?

EDIT

This is the result of echo

enter image description here

This is what I get if I use

--build-arg HDP_VERSION=1 

enter image description here

EDIT2

This is what happens if I use ENV. The result is the same.

ENV HDP_VERSION=${HDP_VERSION}
RUN echo "HDP_VERSION="${HDP_VERSION}

enter image description here

Source: Docker Questions