skip to Main Content

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:a1smyapp.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?

2

Answers


  1. You have to define your resources to that other build pipeline before or after the variables:

    resources:
      pipelines:
        - pipeline: referenceNameOfBuildPipeline
          source: BuildPipelineName
    
      # similarly, referencing another repo source
      repositories:
        - repository: referenceNameOfRepo
          type: git
          name: RepoName
    

    Then you can use the reference name in a download or checkout step:

    steps
      - checkout: self
      - checkout: referenceNameOfRepo
    
      - download: referenceNameOfBuildPipeline
        artifact: 'myApp'
        displayName: 'Downloading myApp'
    
      - task: ExtractFiles@1
        displayName: "Extracting Build Artifacts"
        inputs:
          archiveFilePatterns: "$(Pipeline.Workspace)/**/myapp.zip"
          destinationFolder: '$(Build.BinariesDirectory)'
    
    Login or Signup to reply.
  2. ##[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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search