'/home/vsts/work/1/a' is empty. Nothing will be added to build artifact 'drop

Viewed 245

my yml is very simple. It builds .net proj1 then copies files and again builds proj2 and copies files. Then it drops zip in the output folder. But after successful build I get the message - '/home/vsts/work/1/a' is empty. Nothing will be added to build artifact 'drop. Below is my yml.

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- $(Build.SourceBranchName) 

stages:
- stage: BuildProject
  displayName: buildProj
  jobs:
  - job: Buildproj1
    pool:
      vmImage: 'windows-2019'
      steps:
        - task: VSBuild@1
          inputs:
            solution: 'Proj1Folder/Proj1/Proj1.csproj'
            msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
            platform: 'Any CPU'
            configuration: 'Release'
            #clean: true

        - task: CopyFiles@2
          inputs:
            sourceFolder: $(System.SourcesDirectory)
            contents: '**\*'
            targetFolder: '$(Build.artifactStagingDirectory)'

  - job: BuildProj2
    dependsOn: BuildProj1
    pool:
      vmImage: 'windows-2019'
      steps:
        - task: VSBuild@1
          inputs:
            solution: 'Proj2Folder/Proj2/Proj2.csproj''
            msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
            platform: 'Any CPU'
            configuration: 'Release'
            #clean: true

        - task: CopyFiles@2
          inputs:
            sourceFolder: $(System.SourcesDirectory)
            contents: '!*.dll'
            targetFolder: '$(Build.artifactStagingDirectory)'  

  - job: CreateOutput
    dependsOn: BuildProj2
    steps:
      - task: PublishBuildArtifacts@1
        inputs:
            PathtoPublish: '$(Build.ArtifactStagingDirectory)'
            ArtifactName: 'drop_$(Build.SourceBranchName)'
            publishLocation: 'Container'

      - task: ArchiveFiles@2
        inputs:
            rootFolderOrFile: '$(Build.BinariesDirectory)' 
            includeRootFolder: true 
            archiveType: 'zip' 
            archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' 
            replaceExistingArchive: true 
1 Answers

You are using 3 jobs, each job runs on the new Microsoft-hosted agent, hence in your CreateOutput job, there is no content in target folder.

I tried your yaml, and have same result:

enter image description here

Option1:

Put the tasks in one job, use different folder under $(Build.artifactStagingDirectory) to store the proj1 and proj2 build result, then work on the $(Build.artifactStagingDirectory) for artifact and archive task.

Add the test yaml here:

trigger: none

stages:
- stage: BuildProject
  displayName: buildProj
  jobs:
  - job: Buildproj_1_and_2
    pool:
      vmImage: 'windows-2019'
    steps:
      - task: Bash@3
        inputs:
          targetType: 'inline'
          script: |
            mkdir "$(Build.artifactStagingDirectory)/job1"
            mkdir "$(Build.artifactStagingDirectory)/job2"
      - task: Bash@3
        inputs:
          targetType: 'inline'
          script: |
            echo 'Job1' >> "$(Build.artifactStagingDirectory)/job1/job1.txt"

      - task: Bash@3
        inputs:
          targetType: 'inline'
          script: |
            echo 'Job2' >> "$(Build.artifactStagingDirectory)/job2/job1.txt"

      - task: PublishBuildArtifacts@1
        inputs:
            PathtoPublish: '$(Build.ArtifactStagingDirectory)'
            ArtifactName: 'drop_$(Build.SourceBranchName)'
            publishLocation: 'Container'

      - task: ArchiveFiles@2
        inputs:
            rootFolderOrFile: '$(Build.BinariesDirectory)' 
            includeRootFolder: true 
            archiveType: 'zip' 
            archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' 
            replaceExistingArchive: true 

enter image description here

Option2:

To share files between different jobs, you need to use "PublishPipelineArtifact@1" and "DownloadPipelineArtifact@2"(doc here).

Related