在Azure Devops管道Docker构建任务中将文件内容作为构建参数传递 [英] Pass file content as build argument in azure devops pipeline docker build task

查看:60
本文介绍了在Azure Devops管道Docker构建任务中将文件内容作为构建参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用--build-arg在docker build命令中将文件内容作为build参数传递.我在终端中使用以下命令,并且工作正常

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示例--build-arg PRIVATE_KEY ="$(cat/home/key)"

docker build -t example --build-arg PRIVATE_KEY="$(cat /home/key)" .

但是当我在azure devops管道docker构建任务中尝试相同的事情并在参数框中传递-build-arg PRIVATE_KEY ="$(cat/home/key)" 时,其取值就是 $(cat/home/key)而不执行cat命令.

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.

推荐答案

我不认为这是docker build任务的问题.它适用于命令行任务的原因可能是因为当您在本地计算机上或命令行任务中运行docker build命令时,命令行首先将评估" $()",然后将值传递给docker ARG .但是对于docker build任务,它直接调用docker.exe,这样" $()"中的表达式就可以了.无法评估.

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.

由于找到了使用命令行任务的解决方法.我建议您使用命令行任务而不是docker任务.

Since you have found the workaround to use the command line task. I suggest you use command line task instead of docker task.

我也尝试了@ 4c74356b41的建议.我定义了管道变量 key 并将密钥的值放入此变量中,并在docker build任务中引用此变量.

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.

当我在参数框中放入-build-arg PRIVATE_KEY ="$(key)" 时,我为以下工作.

And i worked for me with below when i put --build-arg PRIVATE_KEY="$(key)" in the Arguments box.

  • 变量

  • Variable

Docker构建任务

Docker build task

这篇关于在Azure Devops管道Docker构建任务中将文件内容作为构建参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆