Combine results of several pipeline jobs into azure web app package

狂风中的少年 提交于 2021-01-28 08:53:10

问题


We're in the process of moving our product to an azure web app. We have an extensive existing pipeline containing multiple parallel jobs. One of these jobs compiles a asp.net web application. Some others compile a vue.js website. Currently, the results of the web application and the vue projects are combined in a separate stage, using a powershell script.

Now I can convert the publish step of the web application to generate a deployment package for azure. But what is the best way of also adding the vue outputs into this package so I can deploy it to azure correctly, without losing the parallel jobs? I cannot include the is output files in my project, because they don't exist within the web application build job


回答1:


You can use publish build artifact task to upload the build results of the web application and vue projects to azure devops server as @Krzysztof mentioned. And you can add a new job to download the artifacts.

Please check below simple example in yaml.

In order to combine the build results, you can use extract file task to extract the zipped artifacts and published the unpacked artifacts in Build_web job. And in the Combine job you can use copy file task to copy the results of vue artifacts to the web artifacts folder. And then you can use archive file task to pack the artifacts which now contains the results of web and vue application.

Combine job should dependsOn Build_web and Build_vue jobs

  jobs:
  - job: Build_Web
    pool: 
      vmImage: "windows-latest"
    steps:
    - task: ExtractFiles@1
      inputs:
        archiveFilePatterns: '*.zip'
        destinationFolder: '$(Build.ArtifactStagingDirectory)\unzip'
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)\unzip'
        artifactName: webapp

  - job: Build_Vue
    pool:  
      vmImage: "windows-latest"
    steps:

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: 'path to the build results'
        artifactName: vueapp

  - job: Combine
    dependsOn:
    - Build_Web
    - Build_Vue
    pool:  
      vmImage: "windows-latest"
      steps:
      - task: DownloadBuildArtifacts@0
        inputs:
          buildType: 'current'
          artifactName: webapp
          downloadPath: "$(System.ArtifactsDirectory)"

      - task: DownloadBuildArtifacts@0
        inputs:
          buildType: 'current'
          artifactName: vueapp
          downloadPath: "$(System.ArtifactsDirectory)"

      - task: CopyFiles@2
        inputs:
          SourceFolder: '$(System.ArtifactsDirectory)\vueapp'
          TargetFolder: 'path to web application result folder'  #eg. $(System.ArtifactsDirectory)\webapp\Content\d_C\a\1\s\AboutSite\AboutSite\obj\Release\netcoreapp2.0\PubTmp\Out\

      - task: ArchiveFiles@2
        inputs:
          rootFolderOrFile: $(System.ArtifactsDirectory)\webapp
          archiveType: 'zip'
          archiveFile: '$(Build.ArtifactStagingDirectory)/webapplication.zip' 

Above example only shows a general idea. You can aslo move the ExtractFile task to Combine job. In either way, you will have to use extract file, copy file and archive file task.

For TargetFolder parameter in copy file task, you can check the download build artifacts log for webapp artifact to get the full path. For example as below screenshot shows.




回答2:


You can use PublishPipelineArtifact@1 to create artifacts for your projects and then in a separate job DownloadPipelineArtifact@2. By defining path you may compose your final artifact (if this mixing many projects is not more complicated than putting one inside another). And publish your artifact as build or pipeline artifact depending how you have roganized your release.

# Download an artifact named 'WebApp' to 'bin' in $(Build.SourcesDirectory)
- task: DownloadPipelineArtifact@2
  inputs:
    artifact: 'WebApp'
    path: $(Build.SourcesDirectory)/bin

Here you have more info about publishing and downloding artifacts.



来源:https://stackoverflow.com/questions/61215880/combine-results-of-several-pipeline-jobs-into-azure-web-app-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!