Issue
I want to pass my file content as build argument in docker build command using --build-arg. I am using following command in terminal and it is working fine
docker build -t example --build-arg PRIVATE_KEY="$(cat /home/key)" .
but when I am trying same thing in azure devops pipeline docker build task and passing --build-arg PRIVATE_KEY="$(cat /home/key)"
in arguments box its taking the value as it is i.e, $(cat /home/key)
and not executing the cat command.
Solution
I do not think it is the docker build task's problem. The reason it worked for command line task is probably because when you run the docker build command on your local machine or in the command line task, the command line first will evaluate what is wrapped in "$()
",and then the value is passed to the docker ARG
. But for docker build task, it directly invokes docker.exe, so that the expression in "$()
" cannot be evaluated.
Since you have found the workaround to use the command line task. I suggest you use command line task instead of docker task.
I also tried what @4c74356b41 suggested. I defined a pipeline variable key
and put the key's value into this variable and reference this variable in docker build task.
And i worked for me with below when i put --build-arg PRIVATE_KEY="$(key)"
in the Arguments box.
Answered By - Levi Lu-MSFT Answer Checked By - Dawn Plyler (WPSolving Volunteer)