Azure Devops ci pipeline cannot build asp.net core project because it is in subfolder of github repo - github

I have to build an asp.net core spa project with angular frontend. So I have made two folders one for asp.net core API and other for an angular project and pushed it on GitHub. I was integrating the project with Azure Pipe Lines! apps in GitHub so that i can easily do ci/cd with Azure devops. Note that I want to build only the API project in the subfolder.
the github link of the project: https://github.com/lazyfahim/tritronv2
and the azure yml pipeline code : https://github.com/lazyfahim/tritronv2/blob/master/azure-pipelines.yml
The error message showing in the build terminal was
MSBUILD : error MSB1003: Specify a project or solution file. The
current working directory does not contain a project or solution file.
##[error]Bash exited with code '1'.
##[section]Finishing: dotnet build Release

You can just edit the yaml and point dotnet build at your specific project file, e.g.:
steps:
- script: dotnet build SomeFolder\SomeProject.csproj --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'

Related

Azure pipeline build artifacts for previous builds

We have a .NET ASP Web form application. Currently we use TeamCity for the CI part. Deployment part is manual. We take the build artifact generated by TeamCity and deploy the artifact manually.
Now we will be using Azure DevOps for complete CICD process. During the POC we have been able to successfully build and deploy the application in IIS. I am new to the azure pipeline and doing POCs to learn it.
In TeamCity, against each build the generated build artifacts are available. So we can easily refer to any specific build and get the build artifact for that specific build. This is useful in case of rollback. We take the last successfully build artifacts and deploy the same in case of any error.
But in Azure is there any build artifacts repository where we can get the all the build artifacts for all the builds of that pipeline ? There is a section "Artifacts" but as per my knowledge this is for publishing as packages across feeds.
Now I have come across JFrog artifact repository https://jfrog.com/artifactory/. But no nothing about this. Need to go through.
Anyone can please let me know , in azure pipelines , where I can get all the build artifacts against all the builds in a pipeline. Is it available against each run in the pipeline or I need to configure it somehow ?
In any release failure , I need to rollback to the last successful deployed artifact version.
Thanks in advance for any guidance on this.
Azure Artifacts is feed source for packages like nuget etc.
And build/pipeline artifact you can find in your build here (of course if you published them):
Here you have documentation about publishing and downloading pipeline artifacts - newer and recommended approach and here about build artifacts
In short what you needs is add this step:
- task: PublishPipelineArtifact#0
displayName: 'Publish pipeline artifacts'
inputs:
targetPath: $(Build.ArtifactStagingDirectory)/
archiveFilePatterns: '**/*.zip'
Of course if your pipeline output is a nuegt package you can publish it to Azure Artifacts.

.NET Core 3.1 API fails when using DevOps CI/CD

Deploying a .NET Core 3.1 API Application to an Azure WebApp fails when using DevOps CI/CD Release Pipeline but succeeds when Publishing from Visual Studio
Create .NET Core 3.1 Api App
Create Azure Web App
Create a new resource of type “Web App”
Publish from Visual Studio
Ok, so that works, now here's what happens when trying to deploy using DevOps CI/CD Release Pipeline..
Deploy via DevOps CI/CD
… create another Web App resource junk-devops-cicd ...
deploy via ci/cd pipeline
Create the Build Pipeline
Create the Release Pipeline
So it fails going through CI/CD pipeline. But not VS Publish Manager
If the first pipeline you created is a CI pipeline (Build pipeline) you need to select the "ASP .net" template not the "Azure web App". this pipeline will restore nuget,build and publish the artifact of your app in the artifact store of AzureDevops. Then your release pipeline will get this artifact and deploy it into Azure.
the "Azure web App" template is a CI/CD template.
I think the mistake you have mad is deleting some essentials steps for building a package, "Use Nuget" and "Nuget restore".
To build an artifact correctly you need to have those steps:
Asp .net build pipline
Your .net core application build task is wrong. i guess solution is not getting build successfully . try visualstudio build instead of netBuild
And make sure your Artifact Build directory path been set correctly. root path should be $(Build.ArtifactStagingDirectory)

Azure Devops deploying Azure C# Function

I'm failing to use the Azure Devops Release management to deploy my Azure Functions.
Build
In the build pipeline, I've got two tasks:
dotnet publish
publich release artifact
This step succeeds
The artifact is published into /drop/a.zip
Release
In this step I have a Dev environment.
and a single task:
Azure Function App Deploy.
Credentials and which app to deploy to is specified.
There is a path specified to the release artifact like so:
I can even browse the path with the browse button in that image. and navigate to and pick the correct zip there.
But once this task runs. it all ends with a
##[error]Error: No package found with specified pattern: D:\a\r1\a\DotnetFunctions-CI\drop\a.zip
I am aware there are other questions here on SO bringing up the same question. however the answers I've seen there does not solve the issue here.
What am I missing?
I've had issue with the release pipeline not finding an artifact. What I've started doing is using the double wildcard search instead of the full path.
That is in my Deploy Azure App Service task inside the release pipeline.
My azure function works:
In Build :
Visual Studio Build Task :
Add following arguments in MSBuild section :
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\$(BuildConfiguration)\\"
here is my build and release:
Build Configuration:
Release :

Why are there no files in my release artifacts directory?

I created a .netcore 2.1 api project and set up Azure DevOps to deploy it to an On-Prem computer using the Windows Agent.
The folder agent_work\r1\a was created on the machine running the agent, however there are no files in it.
I can see that a build did occur and that there is an artifact in my release
What did I miss doing?
[Update]
I can see in the agent job, there is a section which is about downloading an artifact.
It has the error message
There is no build available or the source is not accessible. You can select all artifacts or specify the list of artifacts to be downloaded below.
[Update]
Looks like I need to add a task to the job that is in a stage of my release.
And that task needs to copy the files I want to deploy.
Now the problem is knowing how to specify the source folder.
The strange thing is that it allows me to select a location and then rejects the selected location
There is help that says that if I leave the source folder empty, that will indicate the root of the repo. If I do this the deploy does not error but no files are deployed.
[Update]
I can see in the Get Sources of the Build the message "YOu are in 'detached Head' state. Maybe this has something to do with the problem.
[Update]
In the build pipeline I have
[Update]
When I try to create a new build pipeline I get the following
I select the location to be Azure Repos and the Repository to be vste
then I the azure-pipelines.yml auto-generates as
# ASP.NET Core
# Build and test ASP.NET Core web applications targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/vsts/pipelines/languages/dotnet-core
pool:
vmImage: 'Ubuntu 16.04'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
[Update]
Looks like I might need to select Use The Visual Designer
[Update]
From ollifant's comment I have found the Publish Artifact task.
Now to figure out how to populate it
[Update]
Uh Uh not looking great
I had not used the ASP NET Core (.NET framework) template when creating the agent job in the build template, so the project was not building correctly.
New build pipeline -> Use the visual designer -> Continue -> ASP.NET Core (.Net Framework)

.NET Core Webjob does not publish when deployed through CD in VSTS

I have a dot net core 2.0 console app which I need to publish in Azure as webjob through continuous build and deployment in VSTS. I have created a web app already in Azure and defined CI and CD tasks in VSTS for the console app's project.
The issue is that whenever these tasks run, webapp gets deployed successfully but the webjob does not get deployed. However, it gets deployed when I use the artifact (zip folder created after build process) and upload it manually to Azure webjob section.
I think deploying the artifact using powershell script might be a solution but I have tried zipdeploy API of Kudu as well but to no use. Can someone please help or point me to a reference for extracting the artifact generated from build process and deploy it using CD tasks so that the webjob gets published alongwith webapp.
With general web application, if you link web job project to the web (right click web app in Visual Studio > Add > New Azure WebJob project/Existing project as WebJob), you can refer to these steps below:
Create a new build definition
Add NuGet Tool Installer task
Add NuGet restore task (Path to solution, packages.config: ***.sln)
Add Visual Studio Build task (MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\")
Add Publish Artifact task (Path to publish: $(build.artifactstagingdirectory))
Queue build
Create a new release definition
Add Deploy Azure App Service task (Package or folder: {web app zip file path}; Choose Publish using Web deploy)
Otherwise:
Create a new build definition
Add NuGet Tool Installer task
Add NuGet restore task (Path to solution, packages.config: ***.sln)
Add Visual Studio Build task (/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\" /p:DeployDefaultTarget=WebPublish
Add necessary task to build web job project (e.g. Visual Studio build)
Add Copy Files task to copy web job’ build result to appropriate folder in web app published folder ($(build.artifactstagingdirectory)) (App_Data/jobs/continuous for continuous webjobs or App_Data/jobs/triggered for scheduled and on-demand WebJobs)
Add Archive Files task (Root folder or file to archive: $(build.artifactstagingdirectory); Archive file to create: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip)
Add Publish Artifact task
Create a new release definition
Add Deploy Azure App Service task (Package or folder: {web app zip file path}; Choose Publish using Web deploy)