0
votes

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.

2

2 Answers

2
votes

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.

  • Variable enter image description here

  • Docker build task

enter image description here

0
votes

You need to either put this value into a variable and reference a variable or use a script step to create a variable out of the contents of the file and reference the variable.

an alternative would be to pass the key to the docker build as a context and inside the build extract that value