问题
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