1

I am having a problem setting up an environment variable as part of Releasing my container. in Azure DevOps, I have a bash task in which I am trying to set an environment variable (CUSER)

export CUSER=$(CUSER) && \
echo $(MYPASS) | sudo -S docker run \
-e CUSER \
--name $(CNAME) \
-p 80:80 $(INAME):$(Build.BuildId) &

The container runs but the environment variable is not set. But it is set when I execute the script directly on the host like export CUSER="Dev9" && docker run -e CUSER --name demo1 -p 80:80 myimage:256 I suspect there is a problem with the way my command is formatted but I am not sure where or what.

  • You are using `sudo`. To avoid vulnerabilities, it doesn't preserve the environment variables when running things as root. See https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo – omajid Dec 08 '21 at 02:45

1 Answers1

0

Resolved it by changing how I authenticate sudo.

sudo -S <<< $(MYPASS) echo export CUSER=$(CUSER) && \
docker run -e CUSER \
--name $(CNAME) \
-p 80:80 $(INAME):$(Build.BuildId) &
Dharman
  • 30,962
  • 25
  • 85
  • 135