Pip authenticate task creates new value for PIP_INDEX_URL/PIP_EXTRA_INDEX_URL each time the pipeline runs, preventing docker to reuse cached layer

I am using azure devops classic build pipeline’s pip authenticate task to create a connection to a private package feed. This task creates environment variables PIP_INDEX_URL and PIP_EXTRA_INDEX_URL.

I am passing the above value as an argument into the dockerfile to configure the package source credentials.

ARG EXTRA_INDEX_URL
ENV ENV_EXTRA_INDEX_URL ${EXTRA_INDEX_URL}
RUN pip config set global.extra-index-url "$ENV:ENV_EXTRA_INDEX_URL"
RUN pip install -r requirements.txt

Azure devops Pip authenticate task creates new value for PIP_INDEX_URL/PIP_EXTRA_INDEX_URL each time the pipeline runs preventing docker to reuse cached layer. Is there any way to allow docker image layer re-use when deriving the credentials using the pip authenticate task?

Source: StackOverflow