John
John

Reputation: 25

Build Docker with artifacts in Azure DevOps Pipeline

I would like to do a Java build into pipeline artifact and then put it in docker file. i can't figure out a way to add artifact to a dockerfile in one pipeline I would like one pipeline to build java code and build a docker image with jar.

Upvotes: 0

Views: 1761

Answers (1)

Leo Liu
Leo Liu

Reputation: 76910

Azure DevOps Pipeline - build Docker with artifacts

You could set the target path to $(Build.ArtifactStagingDirectory) for the task build java code.

Then, add a Docker task after above the publish task, configured to "Build" and set the "Build Context" in the task to $(Build.ArtifactStagingDirectory). That's the root path Docker will use for commands like COPY in a Dockerfile.

And set the Dockerfile path in the task to match its location:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "myAppNameHere.dll"]

Since you've set the Docker Build Context to $(Build.ArtifactStagingDirectory), where your app has been published, the COPY command will use that as a "current working directory." The translation of the COPY is "copy everything in $(Build.ArtifactStagingDirectory) to the /app folder inside the container."

Upvotes: 3

Related Questions