3

Is it possible to copy files from one build agent to another and kick it off as a part of the pipeline task?

One build agent is Linux but I need to continue my work on Windows agent.

2 Answers2

2

Following Hanna's solution, attached more detailed working solution:

Agent-1 and Agent-2 are two different machines from a different agent pool.

Agent-1 does 2 steps:

  1. CopyFiles - writes the file 'livne.txt' (can be any pattern) from the default working directory into the artifact's staging directory
  2. PublishPipelineArtifact - publishes an artifact called: 'PROJECT_NAME' contains all the files copied into the default working directory.

Agent-2 does one main task:

  1. DownloadPipelineArtifact - downloads the file 'livne.txt' (can be any pattern) from the 'PROJECT_NAME' artifact into the current agent's working directory.
  2. simple bash script to make sure 'livne.txt' indeed exists on the working directory.
pool:
  name: Agent-1
- task: CopyFiles@2
  displayName: 'Copy txt file'
  inputs:
    SourceFolder: '$(system.DefaultWorkingDirectory)'
    Contents: livne.txt
    TargetFolder: '$(build.ArtifactStagingDirectory)'

- task: PublishPipelineArtifact@1
  displayName: 'Publish Pipeline Artifact'
  inputs:
    targetPath: '$(build.ArtifactStagingDirectory)'
    artifact: 'PROJECT_NAME'

dependsOn: Job_1
pool:
  name: Self Hosted Ubuntu for Docker Multiplatform

steps:
- task: DownloadPipelineArtifact@2
  displayName: 'Download Pipeline Artifact'
  inputs:
    artifactName: 'PROJECT_NAME'
    itemPattern: livne.txt
    targetPath: '$(build.ArtifactStagingDirectory)'

- bash: |
   ls $(build.ArtifactStagingDirectory)
   cat $(build.ArtifactStagingDirectory)/livne.txt
  displayName: 'Bash Script'


Livne Rosenblum
  • 196
  • 1
  • 12
1

I think the best way to do this is typically to publish the files as artefacts of the pipeline and then download those artefacts again on the second agent. I have done this in projects before when one machine is consuming test results from the test agent to build reports.

You might imagine your pipeline would look something like this:

- job: Build
  displayName: Build on Linux
  steps:
    ...
    - task: PublishPipelineArtifact@1
      displayName: Publish Built binaries from Linux
      inputs:
        path: $(Build.SourcesDirectory)/bin/
        artifact: Binaries


- job: Additional
 displayName: Do something with the binaries on windows
 steps: 
   - task: DownloadPipelineArtifact@2
     inputs:
       artifact: Binaries
       targetPath: $(Pipeline.Workspace)/Binaries
   ...

I hope this helps! :)

Hanna
  • 59
  • 4