Use new Deployment Job in Azure DevOps. Can't find artifacts

拜拜、爱过 提交于 2020-05-11 06:35:20

问题


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

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'

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?


回答1:


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.

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)'

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

Hope that helps!




回答2:


It looks like you're trying to deploy before you publish an artifact.

dependsOn: 'Publish'

You need to publish the artifact first. This is the step you have called Artifact.

I'd also expect that the package path you have, $(build.artifactstagingdirectory)/App.Api.zip, won't work. It's probably going to be somewhere under $(System.DefaultWorkingDirectory).




回答3:


It seems that the format is not correct in your yaml.

dependsOn: 'Publish'

You may try to use following instead.

dependsOn: Publish

Here the dependency should be a job object, not a string. In the expression, if the value is string, it must be single-quoted. Please refer to this document.



来源:https://stackoverflow.com/questions/56480932/use-new-deployment-job-in-azure-devops-cant-find-artifacts

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