1
votes

I have a multi-stage azure build pipeline for a nodejs application.

In the first stage, I'm building the source code and copying the artifacts to the staging directory (Build.ArtifactStagingDirectory) and in the third stage of the azure build pipeline, I'm trying to publish artifacts using PublishBuildArtifacts@1 task.

But I'm getting the following warning:

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

I have tried the PipelineArtifacts task also.

Below is the build pipeline overview. enter image description here

azure-pipelines.yml

trigger:
- master
- feature

pool:
  vmImage: 'ubuntu-latest'

stages:
- stage: BuildApplication
  jobs:
  - job: InstallNodejs
    steps:
    - task: NodeTool@0
      inputs: 
        versionSpec: '10.x'
      displayName: 'Step for installing Node.js'

  - job: PrepareSonarCloud
    steps:
    - task: SonarCloudPrepare@1
      inputs:
        SonarCloud: ******
        organization: ****
        scannerMode: 'CLI'
        configMode: 'manual'
        cliProjectKey: ******
        cliProjectName: ******
        cliSources: '.'
      condition: |
        and
        (
          succeeded(),
          eq(variables['Build.Reason'], 'Pull Request'),
          eq(variables['System.PullRequest.TargetBranch'], 'master')
        )

  - job: BuildNodejs
    steps:
      - script: |
          npm install
          npm run build
        displayName: 'npm install and build'

  - job: CopyFiles
    steps:
    - task: CopyFiles@2
      inputs:
        sourceFolder: $(Build.SourcesDirectory)
        targetFolder: $(Build.ArtifactStagingDirectory)
      displayName: Copy Files to Staging Directory

- stage: StaticCodeAnalysis
  jobs:
  - job: AnalyzeSonarcloud
    steps:
    - task: SonarCloudAnalyze@1
      displayName: 'Run SonarCloud code analysis'
      condition: |
        and 
        (
          succeeded(),
          eq(variables['Build.Reason'], 'Pull Request'),
          eq(variables['System.PullRequest.TargetBranch'], 'master')
        )

  - job: PublishCodeAnalysisReport
    steps:
    - task: SonarCloudPublish@1
      displayName: 'Publish SonarCloud quality gate results'
      inputs:
        pollingTimeoutSec: '300'
      condition: |
        and
        (
          succeeded(),
          eq(variables['Build.Reason'], 'Pull Request'),
          eq(variables['System.PullRequest.TargetReason'], 'master')
        )

- stage: UploadArtifact
  jobs:
  - job: PublishBuildArtifact
    steps:
    - task: PublishBuildArtifacts@1  
      inputs: 
        pathtoPublish: $(Build.ArtifactStagingDirectory) 
        artifactName: drop

Here is the log for copy files task. It's copying the files from source directory to staging directory

Here is the log for copy files task. It's copying the files from source directory to staging directory

Below image shows the log for PublishBuildArtifact task

image shows the log for PublishBuildArtifact task

2
Can you hare your copy files task and the logs?Shayki Abramczyk

2 Answers

0
votes

Unable to copy artifacts from one stage to another stage in azure pipeline

That because you are copy the file in the first stage, but publish build artifacts in another stage.

Those two stages are not on the same machine.

Microsoft will recycle the agent and restore it after you use one stage each time. After that, MS will reassign a new agent to the next stage. This is why you copied the file into the corresponding folder, but it was empty when you published it. Because it's not on the same machine.

So, to resolve this issue, we have to use the copy file task and publish build artifacts task in the same stage.

Hope this helps.

0
votes

If you have access to the VSTS agent you can look on the build folder (to check if the build was made properly), and the ArtifactStagingDirectory.