Unable to set environment variable in container

Hi Guys, I want to download artifact to azure devops using below command

az artifacts universal download --organization "https://dev.azure.com/LeicaDDT/" --feed "Upload" --name "admin-portal" --version "* " --path "/root"

Im running following image

docker run -it mcr.microsoft.com/azure-cli

I have to set an environment variable using following command so that it uses that token to perform operation

docker exec -it 32f06d10cfe6 bash export AZURE_DEVOPS_EXT_PAT=3wl<redacted>xzq

But I’m getting error

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "export": executable file not found in $PATH: unknown

Can any one please help me

Even if this would work, then it would only export it in the very -it interactive TTY session that you started with the above command. It would not be available in the running container, so would not be available to the one you already started using docker run -it mcr.microsoft.com/azure-cli.

So, how are you planning to use it?

If you want the environment variable to be available in your Azure CLI, then on a Mac the following run works:

% docker run -e AZURE_DEVOPS_EXT_PAT=3wl...xzq -it mcr.microsoft.com/azure-cli

bash-5.1# echo $AZURE_DEVOPS_EXT_PAT
3wl...xzq

Likewise, when the above is running (with container id 32f06d10cfe6), this exec works:

% docker exec -e MY_ENV=my-value -it 32f06d10cfe6 bash

bash-5.1# echo $MY_ENV
my-value

bash-5.1# echo $AZURE_DEVOPS_EXT_PAT
3wl...xzq

Correct I do not want to do it in interactive mode i want to run set of commands in my docker container to publish artifacts to azure devops universal feed. Where the following steps would involve.

  1. Run Azure CLI image
  2. Enable Devops extension
  3. Set Azure PAT
  4. And publish artifacts generated in Build stage to Azure DevOps

I’m pretty new to docker can you please guide me how to do ?

Using bash -c, like this may work:

% docker run -e AZURE_DEVOPS_EXT_PAT=3wl...xzq mcr.microsoft.com/azure-cli bash -c 'export MY_ENV=some-val; echo $MY_ENV; echo $AZURE_DEVOPS_EXT_PAT; ls -a'

some-val
3wl...xzq
.
..
.dockerenv
bin
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

A Here document may help to keep things readable.