Reputation: 39354
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?
Upvotes: 10
Views: 9846
Reputation: 904
Try using $(Pipeline.Workspace) instead.
You should also do what @wenbo wrote in his answer but I think it's not required, the important part here is $(Pipeline.Workspace):
By default, files are downloaded to $(Pipeline.Workspace)/{artifact}, where artifact is the name of the artifact. The folder structure of the artifact is always preserved.
Upvotes: 2
Reputation: 1451
you need use PublishPipelineArtifact@1 instead of PublishBuildArtifacts@1 if you split the deployment. I was struggling this issue a whole day, hope this can help u.
# - task: PublishBuildArtifacts@1
- task: PublishPipelineArtifact@1
displayName: Publish pipeline Artifacts
inputs:
pathtoPublish: '$(Pipeline.Workspace)'
artifactName: 'coreapidemo'
Upvotes: 3
Reputation: 306
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://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#download
Hope that helps!
Upvotes: 8
Reputation: 707
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.
Upvotes: -5
Reputation: 58980
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)
.
Upvotes: -3