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?
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!
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'
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.
source
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).
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.
Related
I have an ASP.NET Core project in Azure DevOps repository and it gets built OK using the DevOps build pipeline. However, the release over that builds always fails with this error:
No package found with specified pattern.Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
More Details:
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
branches:
include:
- release/*
pool:
vmImage: 'windows-2022'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
projectName: '**/F11.Web.csproj'
runtime: 'win-x64'
steps:
- task: UseDotNet#2
displayName: 'Use .NET 5 SDK (preview)'
inputs:
packageType: 'sdk'
version: '5.0.100-rc.1.20452.10'
vsVersion: '16.8.0'
includePreviewVersions: true
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '$(projectName)'
feedsToUse: 'select'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(projectName)'
arguments: '--no-restore'
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '$(projectName)'
arguments: '-l "console;verbosity=detailed"'
- task: DotNetCoreCLI#2
displayName: 'Publish WebApi'
inputs:
command: publish
publishWebProjects: false
projects: '$(projectName)'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) --runtime -r $(runtime)'
- task: CopyFiles#2
inputs:
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifactName: 'PublishBuildArtifact'
Azure DevOps pipeline release Error: No package found with specified pattern:
First, you could make sure you have generated the artifact for your build pipeline, check it from the build history in the build pipeline.
Second, when you using the release pipeline to deploy the artifact, you need make sure you have select the correct build pipeline.
Third, set the correct configuration for the task IIS web app deploy:
If above not help you, please share the configuration for the task IIS web app deploy with image in your question.
I've been trying to publish a flutter artefact for a while, but keep getting the same error. A lot of the StackOverflow solutions seem to work for .NET, but not in my case. I'm using Flutter Tasks extension to build.
Thanks for the help.
Here's the solution if someone needs it for later. https://gist.github.com/OriginalMHV/bca27623c32dc04a311f6dff837e2d42
stages:
- stage: Build
jobs:
- job: iOSBuild
pool:
vmImage: 'macOS-latest'
steps:
- task: FlutterInstall#0
inputs:
channel: 'stable'
version: 'latest'
- task: FlutterBuild#0
inputs:
target: ios
projectDirectory: $(projectDirectory)
iosCodesign: false
iosTargetPlatform: device
- job: AndroidBuild
pool:
vmImage: 'macOS-latest'
steps:
- task: FlutterInstall#0
inputs:
channel: 'stable'
version: 'latest'
- task: FlutterBuild#0
inputs:
target: apk
projectDirectory: $(projectDirectory)
- stage: CopyAndPublishArtifact
jobs:
- job: CopyArtifactFiles
steps:
- task: CopyFiles#2
inputs:
SourceFolder: $(Build.SourcesDirectory)
TargetFolder: $(Build.ArtifactStagingDirectory)
- job: PublishArtifact
steps:
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)
ArtifactName: drop
Make sure you copy the artifacts in the job that creates them.
Each job (and thus every stage) runs on an agent and the job's directories are cleaned at the start of each job.
So both your build jobs must publish their own artifact and use a unique name. And then you don't need the last stage.
If you want a single artifact with both files, you need to either build both artifacts in a single job, or have the publish job download the 2 artifacts and then create a new, single, artifact with both iOS and Android packages.
I have searched around for a while, but not been able to find a good way to create a "installation bundle" for web service to run on IIS.
My problem is that we need to manually copy files to the on premises servers due to security, and thus not allowed to automate this job. But as far as I can see all the IIS Deployment templates uses Deployment group to distribute the releases to registered servers.
Is there a way to create a Release pipeline for IIS that produce a zip file/artifact that can be downloaded manually from DevOps or from a drop folder instead?
I have made one Release pipeline using tasks CopyFiles#2, FileTransform#1 and UniversalPackages#0 to copy the build artifact, transform the appsettings.json file and publish the package, but this does not add the nesessary files for IIS, such as the web.config file.
Thanx for any responses :-)
This is the build pipeline yml file:
trigger:
- release*
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: build
projects: '**/*.sln'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'dotnet test'
inputs:
command: test
projects: '**/*Tests.csproj'
arguments: '--configuration $(buildConfiguration) --no-restore --collect "Code coverage"'
testRunTitle: 'Unit and Integrtion Tests'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(buildConfiguration) --output $(build.artifactStagingDirectory)'
zipAfterPublish: true
- task: PublishPipelineArtifact#1
displayName: 'publish pipeline artifact'
inputs:
targetPath: '$(build.artifactStagingDirectory)'
artifactName: 'WebAPI'
And the Release pipeline:
Release pipeline
You could directly use a release pipeline which associated with a build pipeline.
Add the related build pipeline under Artifacts, also, remember to add the Publish build artifacts Task under the build pipeline, which will help the release catch the final zip folder.
Then, you could create a Release under Stages, use Manage IISWebsite Task and Deploy IIS Webiste/App Task.
That is enough.
After som twists and turns I ended up with this solution, using a template yml file for Dev and Release.
If anyone have any suggestions for improvments, please comment below.
Hope this can be of help :-)
Pipelines:
azure-pipelines-build-template.yml:
variables:
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
artifactPath: '$(build.artifactStagingDirectory)'
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet build solution'
inputs:
command: build
projects: '**/*.sln'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'dotnet test solution'
inputs:
command: test
projects: '**/*Tests.csproj'
arguments: '--configuration $(buildConfiguration) --no-restore'
testRunTitle: 'Unit and Integrtion Tests'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish to pipeline'
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(buildConfiguration) --output $(artifactPath)'
zipAfterPublish: true
- task: PublishPipelineArtifact#1
displayName: 'publish pipeline artifact Flyttavle'
inputs:
targetPath: '$(artifactPath)'
artifactName: 'WebAPI'
azure-pipelines-dev-build.yml:
trigger:
- dev
pool:
vmImage: 'windows-latest'
extends:
template: azure-pipelines-build-template.yml
azure-pipelines-release-build.yml:
trigger:
- release*
pool:
vmImage: 'windows-latest'
extends:
template: azure-pipelines-build-template.yml
Releases:
I have created 4 releases, Azure_Dev_Deploy and Azure_Release_Deploy which deploys to Azure, and On_Prem_Prod_Deploy and On_Prem_Test_Deploy that creates packages to download for on premise deployment.
Dev_Deploy and Release_Deploy:
Difference here are:
Trigger is set up for changes respectively on dev and release branches
Deployment points to the app service in Azure for respectively dev and release app services
Variables points to Variable groups respectively for dev and release variable substitutions (defined in Library)
Release Pipeline and Tasks for Dev_Deploy and Release_Deploy
(same setup for both, but picture shows the Dev deployment)
And the yaml view of the task:
Deploy Azure App Service:
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Deploy Azure App Service'
inputs:
azureSubscription: '$(Parameters.ConnectedServiceName)'
appType: '$(Parameters.WebAppKind)'
WebAppName: '$(Parameters.WebAppName)'
packageForLinux: '$(System.DefaultWorkingDirectory)/_BEDevBuild/WebAPI.zip'
JSONFiles: '**/appsettings*.json'
On_Prem_Test_Deploy and On_Prem_Prod_Deploy:
Difference here are:
Creates Artifacts respectively for on-prem-test and on-prem-prod
Variables points to Variable groups respectively for on-prem-test and on-prem-prod variable substitutions (defined in Library)
Release Pipeline and Tasks for On_Prem_Test_Deploy and On_Prem_Prod_Deploy
(same setup for both, but picture shows the Test deployment)
And the yaml view of the tasks:
File Transform:
steps:
- task: FileTransform#1
displayName: 'File Transform: on-prem/prod'
inputs:
folderPath: '$(System.ArtifactsDirectory)/_BEReleaseBuild/*.zip'
fileType: json
targetFiles: '**/appsettings*.json'
Universal publish:
steps:
- task: UniversalPackages#0
displayName: 'Universal publish'
inputs:
command: publish
publishDirectory: '$(System.ArtifactsDirectory)/_BEReleaseBuild'
vstsFeedPublish: '********-****-****-****-************/********-****-****-****-************'
vstsFeedPackagePublish: 'on-prem-prod'
packagePublishDescription: 'Package for on premise production'
Download Artifacts:
Then to download the artifacts in the Artifacts feed, I use the following statement from Powershell locally.
PS! As for today it is not possible to download from a REST call for the universal package which ruined my grand plan of creating a download link in the Wiki, but hopefully this will be supported in the future.
on-prem-test:
az artifacts universal download --organization "https://dev.azure.com/[my org name]/" --project "[DevOps project id]" --scope project --feed "on-premise" --name "on-prem-test" --version "*" --path .
on-prem-prod:
az artifacts universal download --organization "https://dev.azure.com/[my org name]/" --project "[DevOps project id]" --scope project --feed "on-premise" --name "on-prem-prod" --version "*" --path .
Tip on parameters:
--version "*" will allways get latest version in the feed for the given package name
--path . downloads the package to where you execute the command in Powershell
I would like to have a pull request launch a build and that build must succeed before merging into the target branch is allowed.
I have master and develop branch and create feature branches from develop. work is completed and then a pull request initiated to merge back into develop.
I have created a build pipeline that completes successfully when run manually.
I have specified in the branch policies for the develop branch that the build must be run and complete successfully.
Now when I create a pull request, it says that in order for the pull request to be approved, the build must run but it does not run the build. What am I doing wrong?
This is a c# .net framework app.
Should I be saving the yaml in the develop branch or master? That part confuses me. Is the trigger correct?
This is my yaml for the build pipeline:
trigger:
- develop
pool:
vmImage: 'windows-latest'
name: '1.0.1.$(Rev:r)'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- checkout: git://OvaFlow/Utilities#develop
- task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: VersionAssemblies#2
inputs:
Path: '$(Build.SourcesDirectory)'
VersionNumber: '$(Build.BuildNumber)'
InjectVersion: true
FilenamePattern: 'AssemblyInfo.*'
OutputVersion: 'OutputedVersion'
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Build.SourcesDirectory)/Utilities/packages.config'
feedsToUse: config
nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.config'
restoreDirectory: '$(Build.SourcesDirectory)/packages'
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Build.SourcesDirectory)/UtilitiesTests/packages.config'
feedsToUse: config
nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.config'
restoreDirectory: '$(Build.SourcesDirectory)/packages'
- task: VSBuild#1
displayName: 'Build solution **\*.sln'
inputs:
solution: '$(Build.SourcesDirectory)/Utilities.sln'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: VSTest#2
displayName: 'VsTest - testAssemblies'
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\*test*.dll
!**\obj\**
codeCoverageEnabled: true
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
continueOnError: true
- task: PublishSymbols#2
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
PublishSymbols: false
continueOnError: true
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**\bin\$(BuildConfiguration)\**'
TargetFolder: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
Should I be saving the yaml in the develop branch or master? That part confuses me. Is the trigger correct?
The answer is yes! In fact, you have already found the answer.
As we know from the Build validation:
Set a policy requiring changes in a pull request to build successfully
with the protected branch before the pull request can be completed.
Build policies reduce breaks and keep your test results passing. Build
policies help even if you're using continuous integration (CI) on your
development branches to catch problems early.
So, the build validation used for the branches which you want to protected, the .yml should saved in the branch which you set the build policy.
As test, if I set the .yml file under the Test branch, then pull request for the dev branch, the build will not be triggered automatically:
Then, I moved the .yml file to the dev branch with a new build pipeline, it works fine:
Hope this helps.
If build is not configured to run automatically on push, you have to run it manually, here:
Or you can configure build to trigger automatic on branch update:
This will build successfully after I have completed a PR, but it's not building as part of the validation of the PR. Also, for some reason when I create a new release from the dev branch, it's not triggering a build there either (and thus one of the conditions I have where it builds on a release branch, it's not creating the artifact for my release pipeline).
The current build validation I have for my branch policy on both Dev and my Releases/* branch
My Azure Pipeline for the API:
trigger:
branches:
include:
- Dev
- Releases/*
paths:
include:
- MCR.API/*
jobs:
- job: api
variables:
configuration: release
pool:
vmImage: 'vs2017-win2016'
steps:
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: '**/*API.csproj'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: '**/*API.csproj'
- task: DotNetCoreCLI#2
displayName: Publish API
inputs:
command: publish
publishWebProjects: false
projects: '**/*API.csproj'
arguments: '--output $(build.artifactstagingdirectory) --configuration $(configuration)'
zipAfterPublish: True
- task: PublishBuildArtifacts#1
displayName: 'Publish API Artifact'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/heads/Releases/'))
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
artifactName: 'API'
I am wanting this to force a PR to dev and Releases/* to have a successful build before it can be completed (it's not doing that). I want it to build after the PR is completed (it IS doing that). I want it to build when a new Release in the Releases/* branch is created (it's not doing that).
So the answer to this problem was rather simple...
In the build validation policy, make sure you have a leading slash in front of your directory - even though you don't need one in your yaml pipelines file.
So far example I changed this:
MCR.API/*
MCR/*
MCR.Admin/*
To:
/MCR.API/*
/MCR/*
/MCR.Admin/*
And everything worked as I wanted.