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

Navin prasad

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

Leo Liu-MSFT

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Retrieving a variable as list passed from one stage to another in Azure pipeline

cannot copy from one stage to another in multi stage docker build

How can I add another git pull from one jenkins pipeline stage

Pass variables from one job to an other in an azure multi stage pipeline (YAML)

Azure DevOps Pipeline: same template twice in one stage

Skipped pipeline stage in Azure devops

how to copy flask dependencies from one stage to the next one in a Dockerfile?

Gitlab pipeline test stage to fail AND create artifacts anyway

Unable to pass variables in Jenkins Pipeline Post Stage

Azure: Unable to copy Archive blobs from one storage account to another?

Jenkins pipeline: detect if a stage is started with the "Restart from stage" icon

Scheduled trigger in Azure Pipeline multistage for a spesific stage

Azure release pipeline, continue after failed stage

Approving pipeline stage azure devops via API

Multi Stage YAML Azure Pipeline Variable Scope

How to know if a stage is rejected by environment in Azure Pipeline?

How to conditionally fail an Azure Devops Pipeline stage?

Multi stage build can't COPY file from previous stage

Create Stage that can be Called from Another Stage or Manually?

In Dockerfile, do I have to COPY the files from stage "a" to stage "b" if stage "b" is defined as "FROM a AS b"?

gitlab ci: Pass artifacts from two jobs of the same stage

COPY from named stage fails with `no such file or directory`

Snowflake COPY INTO from stage losing rows

trying to use set variable from predefined variables and use it in condition for stage in azure devops pipeline

Using azure powershell to copy data from one slot to another in pipeline/release

Azure Pipeline- Copy files from one Repo to another Repo using YAML

How to copy or moves files from one directory to another directory inside the Kubernetes POD (Azure Devops release Pipeline)

Pipeline not moving to next stage

Unrecognized pipeline stage name: '$and'