Search code examples
devopspipelineazure-artifacts

devops pipeline fails, artifact not found


I have an azure devops pipeline that publishes output,

pool:
vmImage: 'windows-latest'
steps:
- script: |
    dotnet restore
    dotnet build --configuration Release
- task: DotNetCoreCLI@2
  inputs:
    command: publish
    arguments: '--configuration Release --output publish_output'
    projects: 'MyProject/*.csproj'
    publishWebProjects: false
    modifyOutputPath: false
    zipAfterPublish: false
- task: ArchiveFiles@2
  displayName: "Archive files"
  inputs:
    rootFolderOrFile: "$(System.DefaultWorkingDirectory)/publish_output"
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/myapp.zip"
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/myapp.zip'
    artifactName: 'myapp'

and this works.

Another release pipeline should use the artifact generated by build,

trigger:
- main

variables:
  azureSubscription: MySubscription
  appName: myAppName
  vmImageName: 'ubuntu-latest'

steps: 

- task: DownloadBuildArtifacts@1
  inputs:
    buildType: 'current'
    downloadType: 'single'
    artifactName: 'myapp'
    downloadPath: '$(Build.ArtifactsDirectory)'
- task: AzureFunctionApp@1 # Add this at the end of your file
  inputs:
    azureSubscription:  $(azureSubscription)
    appType: functionApp # default is functionApp
    appName: $(appName)
    package: $(Build.ArtifactsDirectory)/**/*.zip

but this fails already in the DownloadBuildArtifacts task with error:

##[error]Artifact myapp was not found for build xy.

I can see in the log that the artifact is placed in some folder,

Upload 'D:\a\1\s\myapp.zip' to file container: '#/29596927/myapp'

but there is no info in which location the DownloadBuildArtifacts task is searching for the artifact (at least I did not find it even with analytics enabled in the pipeline run). Should I replace 'Build.ArtifactsDirectory' or is something wrong at another place?


Solution

  • ##[error]Artifact myapp was not found for build xy.

    From your YAML sample, the cause of the issue is that you need to download the artifacts from Build Pipeline, but in release pipeline, you add the DownloadBuildArtifacts task to download the current release pipeline artifacts.

    buildType: 'current'

    Since the build artifacts doesn't exist in release pipeline, it will cause the issue.

    To solve this issue, you need to modify the DownloadBuildArtifacts task definition to download the build pipeline artifacts.

    For example:

    steps:
    - task: DownloadBuildArtifacts@1
      displayName: 'Download Build Artifacts'
      inputs:
        buildType: specific
        project: 'projectname'
        pipeline: 'Pipelinename or PipelineID'
        artifactName: 'myapp'
        downloadPath: '$(Build.ArtifactsDirectory)'
    

    In this case, it will download the artifacts of Build Pipeline.

    For more detailed info, you can refer to the doc: DownloadBuildArtifacts@1