中使用新的部署作业

中使用新的部署作业

本文介绍了在 Azure DevOps 中使用新的部署作业.找不到文物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Azure Devops 将 Asp.Net Core 应用程序部署到 Azure WebApp.

I need to deploy an Asp.Net Core Application to Azure WebApp using Azure Devops.

我有以下工作 Azure-Pipelines YAML 文件:

I have the following working Azure-Pipelines YAML file:

trigger:
- master

variables:
  buildConfiguration: 'Release'
  buildPlatform: 'any cpu'
  version: '0.2.0'

stages:

- stage: 'Stage1'

  jobs:

  # Previous Jobs like Build, Test, ...

  - job: 'Publish'
    pool:
      vmImage: 'Ubuntu-16.04'
    dependsOn: 'Test'
    steps:

    - task: DotNetCoreCLI@2
      displayName: 'Publish'
      inputs:
        command: publish
        publishWebProjects: false
        projects: '**/*.csproj'
        arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
        zipAfterPublish: true

    - task: PublishBuildArtifacts@1
      displayName: 'Artifact'
      inputs:
        PathtoPublish: '$(build.artifactstagingdirectory)'

    - task: AzureRmWebAppDeployment@4
        displayName: 'Deploy'
        inputs:
          package: '$(build.artifactstagingdirectory)/App.Api.zip'
          azureSubscription: 'MyName.Azure'
          appType: 'Web App On Windows'
          webAppName: 'myname-api'

这很好用,但我想使用新的 部署作业.

This works fine but I would like to use the new Deployment Job.

我删除了部署"任务,并在发布"作业之后将其添加为新的部署作业:

I removed the 'Deploy' task and added it as a new Deployment Job after the 'Publish' job:

  - deployment: DeployJob
    dependsOn: 'Publish'
    pool:
      vmImage: Ubuntu-16.04
    environment: production
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureRmWebAppDeployment@4
            inputs:
              package: '$(build.artifactstagingdirectory)/App.Api.zip'
              azureSubscription: 'MyName.Azure'
              appType: 'Web App On Windows'
              webAppName: 'myname-api'

您可以看到AzureRmWebAppDeployment@4"与之前相同.

You can see that the 'AzureRmWebAppDeployment@4' is the same as before.

但是现在运行管道时出现以下错误:

But now I get the following error when I run the pipeline:

Download artifact to: /home/vsts/work/1/
Could not find any pipeline artifacts in the build.

我错过了什么?如何解决这个问题?

What am I missing? How to fix this?

推荐答案

我自己一整天都在为此苦苦挣扎,直到跌跌撞撞地找到了解决方案.似乎有一些默认的助手"任务被捆绑到作业中,并且部署作业有一个默认的下载任务被添加.我仍然不确定它在我的情况下尝试下载什么,但它导致了您描述的相同问题.

I've struggled with this all day myself, until stumbling into a solution. It seems there are a few default "helper" tasks that get bundled into the jobs, and the deployment jobs have a default download task that gets added. I'm still not sure what it was trying to download in my case, but it was causing the same problem you describe.

尝试将 - download: none 任务添加到部署作业的步骤中,并改为明确指定任务.这样的事情应该可以工作:

Try adding a - download: none task to your deployment job's steps, and specifying the tasks explicitly instead. Something like this should work:

  - stage: deploy_dev
    displayName: Development environment
    jobs:
    - deployment: Deploy
      displayName: Deploy to Development environment
      environment: myproject-dev
      pool:
        vmImage: ubuntu-16.04
      strategy:
        runOnce:
          deploy:
            steps:
            - download: none
            - task: DownloadBuildArtifacts@0
              inputs:
                artifactName: $(ArtifactName)
                buildType: 'current'
                downloadType: 'single'
                downloadPath: '$(System.ArtifactsDirectory)'

可在此处找到下载快捷方式的文档:https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#download

Documentation for the download shortcut can be found here: https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#download

希望有帮助!

这篇关于在 Azure DevOps 中使用新的部署作业.找不到文物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:24