Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy an Azure DevOps build artifact to a Docker image build in the same pipeline?

In an Azure DevOps pipeline after downloading an artifact from a previous stage like this:

- download: 'current'
    artifact: my_artifact

I want to reuse it in the Dockerfile of this Docker build task:

- task: Docker@2
  displayName: Build
  inputs:
    command: build
    containerRegistry: myConnection
    repository: myRepository

like this:

COPY *.whl /myDir/

After the COPY command the target directory is still empty. Where are the files from the artifact and how do I copy them in the Dockerfile?

like image 685
Corbie Avatar asked Oct 16 '25 21:10

Corbie


1 Answers

The solution is to copy the artifact from where it is downloaded to ($(Pipeline.Workspace)/my_artifact) to the PATH directory, of the build command ($(Build.SourcesDirectory)):

- bash: cp $(Pipeline.Workspace)/my_artifact/*.whl $(Build.SourcesDirectory)

Alternatively use the CopyFiles command:

- task: CopyFiles@2
  inputs:
    sourceFolder: '$(Pipeline.Workspace)/my_artifact'
    contents: '*.whl' 
    targetFolder: $(Build.SourcesDirectory)
like image 66
Corbie Avatar answered Oct 20 '25 09:10

Corbie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!