Home > other >  Azure Pipelines - what is the purpose of publishing artifacts?
Azure Pipelines - what is the purpose of publishing artifacts?

Time:11-25

I am new to Azure Pipelines and I was wondering what is the purpose of publishing artifacts. For example I have the code below:

    - task: ArchiveFiles@2
  inputs:
   rootFolderOrFile: '$(Build.SourcesDirectory)'
   includeRootFolder: false
   archiveType: 'zip'
   archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'  
   replaceExistingArchive: true
   displayName: Archive files

- task: PublishBuildArtifacts@1
  inputs:
   pathToPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' 
   artifactName: 'drop' 
     
- task: AzureFunctionApp@1
  inputs:
   azureSubscription: $(azureSubscription)
   appType: 'functionAppLinux'
   appName: $(appName)
   package: '$(System.ArtifactsDirectory)/**/*.zip'
   displayName: Deploy Azure Function

Which could be replaced by skipping the PublishBuildArtifacts:

- task: ArchiveFiles@2
  inputs:
   rootFolderOrFile: '$(Build.SourcesDirectory)'
   includeRootFolder: false
   archiveType: 'zip'
   archiveFile: $(System.ArtifactsDirectory)/build$(Build.BuildId).zip  
   replaceExistingArchive: true
   displayName: Archive files

- task: AzureFunctionApp@1
  inputs:
   azureSubscription: $(azureSubscription)
   appType: 'functionAppLinux'
   appName: $(appName)
   package: '$(System.ArtifactsDirectory)/build$(Build.BuildId).zip'
   displayName: Deploy Azure Function

Which one is better and why?

CodePudding user response:

Well, if you put all in one job it doesn't make a sense to have artifact published apart from the fact that you can always download and check locally your artifacts. However, it makse bigger sense when you split build, test and publish artifact into one job and deployment into second. Why?

  • because when your deployemnt fails you can retry just deplyment without building package again
  • you may want to deploy package into several apps and then you can do this in parallel spliting deployment into several jobs
  • you can use just for deployment a special job (deployment job) which has nice features very useful for deployment process (approval, exclusive locks etc) - of course you ma use this job also for building, however this dedicated job has some limitation for instance can have only one checkout (so if you have more you can't use it). It download by default all avaliable artifacts to make work easier.
  • Related