I'm facing a problem deploying an angular universal app in azure web service I followed this step https://stackoverflow.com/a/53616516/10979521 but a got an error says
##[error]Error: Publish using webdeploy options are supported only when using Windows agent.
I guess the issue occurs in creating an app service, in my app service settings
(
*publish (code)
*runtime stack (.NET Core 2.2)
*Operating System (Windows)
)
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install -g #angular/cli
npm install
npm run build:ssr
displayName: 'build the project'
- task: CopyFiles#2
displayName: 'Copy dist files to staging'
inputs:
SourceFolder: '$(Build.SourcesDirectory)/dist'
TargetFolder: '$(Build.ArtifactStagingDirectory)/app/dist'
- task: CopyFiles#2
displayName: 'Copy server.js to the root'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)/app/dist'
Contents: server.js
TargetFolder: '$(Build.ArtifactStagingDirectory)/app'
- task: DeleteFiles#1
displayName: 'Delete the dist/server.js'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)/app/dist'
Contents: server.js
- task: AzureRmWebAppDeployment#3
displayName: 'Azure App Service Deploy: website'
inputs:
azureSubscription: 'my subscription'
WebAppName: 'my website'
Package: '$(Build.ArtifactStagingDirectory)/app'
GenerateWebConfig: true
WebConfigParameters: '-Handler iisnode -NodeStartFile server.js -appType node'
UseWebDeploy: true
RemoveAdditionalFilesFlag: true
Edit 2 (9/3/2020)
Microsoft is moving away from release pipelines.
"Classic Release Pipelines"
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/?view=azure-devops
New "Pipelines"
https://learn.microsoft.com/en-us/azure/devops/pipelines/create-first-pipeline?view=azure-devops&tabs=java%2Cyaml%2Cbrowser%2Ctfs-2018-2
Edit:
I realized after I typed this up that maybe your problem is you have "UseWebDeploy: true" and maybe you can fix your problem by setting this to false. Below is a screenshot taken from the same task setup in a release pipeline.
I still think your best option is to remove the deploy task from your build pipeline as outlined below since build pipelines are not meant to be used in this way. But that is up to you.
Original Answer:
Remove this part from your build pipeline:
- task: AzureRmWebAppDeployment#3
displayName: 'Azure App Service Deploy: website'
inputs:
azureSubscription: 'my subscription'
WebAppName: 'my website'
Package: '$(Build.ArtifactStagingDirectory)/app'
GenerateWebConfig: true
WebConfigParameters: '-Handler iisnode -NodeStartFile server.js -appType node'
UseWebDeploy: true
RemoveAdditionalFilesFlag: true
Add a publish step to the end of you build.yml file. This will allow your release pipeline to pick up the artifacts from your build.
- task: PublishBuildArtifacts#1
Setup a release pipeline to deploy your build.
Create a new pipeline
Add the artifact from your build
Then add a stage (ie Dev, QA, Production)
Select "empty job"
Edit the stage and add tasks
Add the Azure App Service task
Update the version number on the Azure App Service Deploy to version 3 (the same one you are using in your yaml - AzureRmWebAppDeployment#3).
Fill in the values in the task the same way you have it in your yaml.
The default value for the "Package or folder" option probably isn't correct. You can use the 3 dots on the right to navigate and select the correct folder. If you click this and see nothing then this is most likely because you haven't kicked off a build yet with the above "PublishBuildArtifact#1" change.
Keep working your way down and expanding the options to find your other configuration settings.
If you are having trouble with anything you can verify the task is setup properly by scrolling to the top of the task and clicking "View YAML". Then you can compare to your original yaml.
Hopefully this helps.
Related
I've got a build pipe for an Azure Function using .Net Core 3.1.x. All the steps until the publishing are doing fine. I can get the publish step working by using script, but not through the yaml task. What am I missing?
Script (works)
- script: dotnet publish --configuration Release .\af-process-mds-vehicle-output-to-deviation\af-process-mds-vehicle-output-to-deviation.csproj
Task (does not work)
- task: DotNetCoreCLI#2
displayName: 'Publish Project'
inputs:
command: 'publish'
configuration: 'Release'
projects: '.\af-process-mds-vehicle-output-to-deviation\af-process-mds-vehicle-output-to-deviation.csproj'
zipAfterPublish: true
It doesn't find the project.
Here's the error message.
2021-10-29T05:21:44.3024816Z ##[section]Starting: dotnet publish
2021-10-29T05:21:44.3150367Z ==============================================================================
2021-10-29T05:21:44.3150726Z Task : .NET Core
2021-10-29T05:21:44.3151190Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2021-10-29T05:21:44.3151475Z Version : 2.187.0
2021-10-29T05:21:44.3151733Z Author : Microsoft Corporation
2021-10-29T05:21:44.3152035Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2021-10-29T05:21:44.3152373Z ==============================================================================
2021-10-29T05:21:44.7797987Z [command]C:\Windows\system32\chcp.com 65001
2021-10-29T05:21:44.7903026Z Active code page: 65001
2021-10-29T05:21:44.7927221Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2021-10-29T05:21:44.8938257Z ##[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file, wwwroot folder in the directory, or by the usage of Microsoft.Net.Web.Sdk in your project file. You can set Publish web projects property to false (publishWebProjects: false in yml) if your project doesn't follow this convention or if you want to publish projects other than web projects.
2021-10-29T05:21:44.9001249Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2021-10-29T05:21:44.9003648Z ##[error]Project file(s) matching the specified pattern were not found.
2021-10-29T05:21:44.9182124Z ##[section]Finishing: dotnet publish
After the tips from the answer I got the pipe working. Here's the full working pipe. (Still don't know why it didn't work earlier.)
Working pipe:
name : af-vehicle-sync-to-deviation
## if there is a change is the deviation folder for the main branch. Then trigger.
trigger:
branches:
include:
- main
paths:
include:
- af-process-mds-vehicle-output-to-deviation/*
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
SolutionPath: '**\*.sln'
stages:
- stage: Build
displayName: Build solution
jobs:
- job: Build
displayName: Build and publish solution
steps:
- checkout: self
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: $(SolutionPath)
- task: UseDotNet#2
inputs:
packageType: 'sdk'
version: '3.1.x'
displayName: 'Use .NET Core SDK 3.1.x'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
configuration: $(buildConfiguration)
projects: '$(SolutionPath)'
displayName: 'Build solution'
- task: DotNetCoreCLI#2
displayName: 'Publish Project'
inputs:
command: 'publish'
configuration: 'Release'
projects: '**\*.csproj'
publishWebProjects: false
zipAfterPublish: true
arguments: '--output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
You could use '**/*.csproj' but honestly, I would do something like this answer and add a script to list out all the files and folders recursively before this step that fails.
Assuming that you have a restore or build step before this publish you could add it after those, or just as the first step after your checkout one.
You can also inspect the logs of earlier steps to see the file path/s., instructions on doing this are available here.
Using $(System.DefaultWorkingDirectory) as your root is also recommended, rather than .\, so you would have '$(System.DefaultWorkingDirectory)\af-process-mds-vehicle-output-to-deviation...'.
Edit
If you look at the logs for your build step you will see entries like /home/vsts/work/1/s/XXX.YYY.ZZZ/XXX.YYY.ZZZ.csproj that refer to the different projects inside your solution. By default most commands will be run in $(System.DefaultWorkingDirectory) which would equate to /home/vsts/work/1/s/ in this instance, you can think of it as the root of your repository - there is more information on this structure here.
The error you were encountering is actually about the lack of a web project, rather than a path issue though, for the build step it is best practice to use the --output <output-directory-here> flag to output the compile files into a specific folder, that way you can easily publish that folder.
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'm using Azure Dev Ops to run my build and release pipelines. I've got a build script that publishes my web code to an artifact folder (using .NET SDK projects), and I just need to push this code into my Azure app service. I've tried the "Azure app service deploy" and "Deploy code to app service" tasks in the release pipeline, giving it the publish settings file from my Azure instance and pointing to the folder with my code (since it says it takes zip or folder). On the console at this step, however, I get an error message of "No such deploying method exists."
I was able to get things pushed through FTP but I'd like to understand why the app service publish didn't work, as there are options (like deployment slots) that might be needed in the future. Is this a scenario where using the Azure resource manager connection would work better? Or does my build artifact need to be zipped after all? If it has to be zipped as a web deploy, is there a step to do this after a solution build, because I have to copy files into the artifact folder for transforms first, so I can't just do a comprehensive web build/zip.
I don't see details of your pipeline so I would share mine. I'm deploying zip package:
In Package or folder dialog I have:
I use YAML in my pipelines but it is easy to understand and follow if you want to have similar in classic pipelines:
trigger: none
pr: none
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
projectDirectory: 'app-service-deployment-to-slot-with-preview\hadar'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
workingDirectory: $(projectDirectory)
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: '$(projectDirectory)\hadar.csproj'
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: CopyFiles#2
displayName: 'Copy configuration settings checks'
inputs:
contents: app-service-deployment-to-slot-with-preview\scripts\**
targetFolder: '$(Build.ArtifactStagingDirectory)\scripts'
flattenFolders: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifacts'
I am doing a simple Azure DevOps CICD deployment. I am following all the steps. First up, here is my YAML file. I have kept the comments as it is, just in case, I am making more mistakes than I am aware of.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
# Set variables
variables:
directory: ReactJSRecipeApp
steps:
- task: NodeTool#0
inputs:
versionSpec: '12.13.0'
displayName: 'Install Node.js'
- script:
npm install
displayName: 'npm install'
- script:
npm run build
displayName: 'npm build'
- task: CopyFiles#2
displayName: 'Copy files'
inputs:
sourceFolder: 'build'
Contents: '**/*'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
cleanTargetFolder: true
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Build Artifacts'
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
ArtifactName: 'www' # output artifact named www
- task: AzureWebApp#1
displayName: 'Deploy to App Service'
inputs:
azureSubscription: 'ReactJSRecipeAppConnection'
appName: 'reactjsrecipeappwebapp2'
appType: 'webApp'
package: '$(System.ArtifactsDirectory)/$(Build.BuildId).zip'
customWebConfig: '-Handler iisnode -NodeStartFile server.js -appType node'
So, when I run this, I get no errors in the Pipeline.
Further, I want to point out the following.
If I download the artifacts zip folder, I am able to run that folder locally and get my react app running in a localhost server just fine.
I check my Azure web app via Kudo Tools, I see all the files inside wwwroot, with timestamps that match the zip file from the artifact folder. So, I am assuming that the files are indeed getting pushed and to the correct spot in the web server.
Before I run the CICD trigger, these azure web apps were created brand new, and I get the standard azure welcome/landing page. So, the web apps themselves are fine.
After all this, the website itself does not serve the pages. I get a 404. I have tried two different web apps on Azure but the same results.
Any advise, where I am going wrong?
Update 1
I decided to manually check the files on Filezilla. But, its empty!!!
But, KUDO shows files. I dont understand!
Update 2
So, I did a direct deploy from visual studio code with the artifact publish folder. the web app runs fine. So, did this step to make sure that the web app is configured correctly.
Alright, so, it looks like my YAML file was not correct. I finally got it to work.
I am posting it here if someone comes around looking for a ready to use React YAML file (because the Azure DevOps Documentation is not that useful in its current form)
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- task: CopyFiles#2
inputs:
Contents: 'build/**' # Pull the build directory (React)
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory) # dist or build files
ArtifactName: 'www' # output artifact named www
# Default value: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/build/'
includeRootFolder: false
- task: AzureWebApp#1
inputs:
azureSubscription: 'ReactJSRecipeAppConnection'
appName: 'ReactJSRecipeApp4'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
The full repository with simple react code including the YAML is here.
https://github.com/Jay-study-nildana/ReactJSRecipeApp
I am struggling to get a simple build and deploy working and was hoping for some assistance. Could anyone review the steps and also why the Publish Artifacts does not work? It's a simple Angular 7 project.
Error:
[section]Starting: Publish Artifact: dist
========================================================================== Task: Publish Build Artifacts Description: Publish build
artifacts to Azure Pipelines/TFS or a file share Version:
1.142.2 Author : Microsoft Corporation Help : More Information
[warning]Directory 'D:\a\1\s\dist' is empty. Nothing will be added to build artifact 'dist'.
[section]Finishing: Publish Artifact: dist
YAML:
pool:
vmImage: Hosted VS2017
demands: npm
steps:
- script: |
echo Write your commands here
mkdir dist
echo Use the environment variables input below to pass secret variables to this script
displayName: 'Command - mkdir dist'
- task: Npm#1
displayName: 'npm install'
inputs:
verbose: false
- task: Npm#1
displayName: 'npm build'
inputs:
command: custom
verbose: false
customCommand: 'build --prod'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: dist'
inputs:
PathtoPublish: dist
ArtifactName: dist
- task: FtpUpload#1
displayName: 'FTP Upload: dist'
inputs:
credentialsOption: inputs
serverUrl: ‘xxx’
username: Tester2
password: 'Tester$2'
rootDirectory: dist
filePatterns: '*'
remoteDirectory: /
trustSSL: true
Azure DevOps Pipeline issue
The Publish Build Artifacts task is used to publish build artifacts to Azure Pipelines, TFS, or a file share.
But, just like Daniel and Andrey said, although you add the npm build, you did not set the installed folder to be dist. So the result of npm build will not be saved in the dist folder. In this case, the folder dist is empty.
Besides, to save the build result to the dist folder, you can try to use the option -- -op like following:
run ng build --prod -- -op ..\..\dist
The ..\..\dist should use relative path based on the project.json file.
Check the document JavaScript frameworks: AngularJS for some more details info.
Hope this helps.