问题
I want to get the data from the variable Build.Repository.LocalPath
and use it in my Dockerfile, but it shows me and error.
This is my dockerfile:
FROM microsoft/aspnet:latest
COPY "/${Build.Repository.LocalPath}/NH.Services.WebApi/bin/Release/Publish/" /inetpub/wwwroot
I get this error:
Step 2/9 : COPY "/${Build.Repository.LocalPath}/NH.Services.WebApi/bin/Release/Publish/" /inetpub/wwwroot
failed to process "\"/${Build.Repository.LocalPath}/NH.Services.WebApi/bin/Release/Publish/\"": missing ':' in substitution
##[error]C:\Program Files\Docker\docker.exe failed with return code: 1
I have try a lot of ways, putting this line:
COPY "/${Build.Repository.LocalPath}/NH.Services.WebApi/bin/Release/Publish/" /inetpub/wwwroot
回答1:
You can add in the Dockerfile an argument:
ARG path
In the Azure DevOps Docker task add an argument:
-task: Docker@2
inputs:
command: build
arguments: --build-arg path=$(Build.Repository.LocalPath)
Now the Dockerfile know the variable value and you can use it, for example:
FROM ubuntu:latest
ARG path
ECHO $path
Results:
Step 3/13 : RUN echo $path
---> Running in 213dsa3dacv
/home/vsts/work/1/s
But if you will try to copy the appliaction in this way:
FROM microsoft/aspnet:latest
ARG path
COPY $path/README.md /inetpub/wwwroot
You will get an error:
COPY faild: CreateFile \?\C:\ProgramData\docker\tmp\docker-builder437597591\_work\1\s\README.md: The system cannot find the path specified.
It's because the Docker build the image within a temporary folder and he copy the sources to there, but he doesn't copy the agent folders (_work/1/s) so the best way it's just put a relative path where the Dockerfile exist, for example (if the Dockerfile exist with the README.md):
FROM microsoft/aspnet:latest
COPY README.md /inetpub/wwwroot
回答2:
build variables are not available in the dockerfile, but that doesnt matter, as if you put the docker file in the repo root, you can use relative path, so this would work:
COPY "/NH.Services.WebApi/bin/Release/Publish/" /inetpub/wwwroot
来源:https://stackoverflow.com/questions/56306821/get-the-data-of-build-repository-localpath-and-used-it-in-my-dockerfile