VSTS release pipeline cant find released artifact - continuous-integration

I'm trying to setup a CI/CD without much luck. My aim is to build a .net web project trough VSTS and deploy it to a AWS Beanstalk app.
Where am I so far?
Created a vsts-ci.yml file as following:
# ASP.NET
# Build and test ASP.NET web applications.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/vsts/pipelines/apps/aspnet/build-aspnet-4
pool:
vmImage: 'VS2017-Win2016'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
And I have a build definition like below:
With this my first step build runs correctly. Btw Agent pool is Hosted VS2017.
Then I have created a release pipeline like below:
And as the Stage 1 tasks (the part that runs after artifact step), I have following:
I have hooked the build to a master branch commit, and hooked the release to a successful build, these triggerings works correctly. Though it fails. The problem is caused by not found artifact files probably because of wrong path inputs. But I don't know the correct versions.
After build finishes, it claims it created a .zip file containing the published version:
But after this, the release fails, only by saying no such file. I have tried many paths at Web Deploy Archive field, but none of them could find the zip file.
The powershell task you see, I created it to check the paths, and what they have in them, and they are mostly empty.
One interesting thing I figured is, build puts the files in D:\a\1\a but release tasks try to look into D:\a\r1\a when I suffixed the Web Deploy Archive field with $(System.defaultWorkingDirectory) and $(Build.artifactStagingDirectory).
Another odd thing is that on release Download artifact stage, it says Linked artifact count: 0. Which I would expect to be something else.
What am I doing wrong here? If someone can guide me trough, I would appreciate.
Update: I've added "Publish Artifact: drop"
When Path to publish is "$(System.DefaultWorkingDirectory)/project-2-codes.zip"
Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\r1\a\project-2-codes.zip
When Path to publish is "$(System.DefaultWorkingDirectory)"
Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\r1\a\$(Build.ArtifactStagingDirectory)

After a lot of head banging to the walls, I've found out the problem.
I was creating the build definition all wrong. I have used the default wizard thing, without noticing the custom designer (I don't think the text next to the link and the name of the link makes any sence).
And it was creating an almost empty build definition. I didn't even understood what it was doing. Now, using the visual designer I can actually select a buil definition template with all the required build tasks in it. After creating the build correctly, everything worked just nice.
Here is the build definition I came up with:
And here is the beanstalk deployment task:

You need to publish your build outputs as an artifact. Use the Publish Artifact task.

Related

Is there a way to have an Azure Pipeline only build specific projects in a solution?

I have an Azure Pipeline that builds all the projects within a solution, but I want to pick and choose which projects get built or ignored by the pipeline. I think that having a "ToBuildBool" boolean to flag which projects are to be built or not is the way to go. The "ToBuildBool" is set as "true" by default and can be set to "false" manually in the csproj files of the projects I do not want built by the pipeline, but rather to be ignored. Am I on the right track? How do I set the boolean flag in a csproj file?
- task: DotNetCoreCLI#2
displayName: 'DotNetCore Build'
inputs:
command: 'custom'
custom: 'build'
projects: 'MySolution.sln'
feedsToUse: config
nugetConfigPath: nuget.config
arguments: '-c Release -p:ToBuildBool=true' # set build flag'
You can specify multiple projects to the projects parameter. That's why it's plural, not singular. Refer to the documentation for the DotNetCoreCLI#2 task for examples of supported patterns.
Or you can have multiple sequential invocations of the DotNetCoreCLI#2 task, one per project you'd like to build.

Deploy a specific project to NuGet with a matrix configuration

My appveyor.yml looks like below:
environment:
matrix:
- solution_name: Src/App1.sln
- solution_name: Src/App2.sln
before_build:
- cmd: dotnet restore %solution_name%
build:
project: '%solution_name%'
publish_nuget: true
after_build:
- dotnet pack Src\App1.csproj
deploy:
- provider: NuGet
api_key:
secure: [my api key]
on:
branch: master
artifact: /.*(\.|\.s)nupkg/
artifacts:
- path: Out\
name: App1
- path: '**\*.nupkg'
It works well with one catch: it seems deploy twice during the build process. Below is part of the AppVeyor log:
Collecting artifacts...
Found artifact 'Out' matching 'Out' path
Found artifact 'Out\App1\Release\App1.6.0.3.nupkg' matching '**\*.nupkg' path
Uploading artifacts...
[1/2] App1.6.0.3.nupkg (164,127 bytes)...100%
[2/2] Out\App1\Release\App1.6.0.3.nupkg (164,127 bytes)...100%
Deploying using NuGet provider
Publishing App1.6.0.3.nupkg to https://www.nuget.org/api/v2/package...OK
Publishing App1.6.0.3.nupkg to https://www.nuget.org/api/v2/package...Skipped (A package with ID 'App1' and version '6.0.3' already exists and cannot be modified.)
No packages were pushed.
So I login NuGet.org and I can see App1.6.0.3 is published successfull. However, in the above log, the same package is published twice, hence the second publish is skipped, and end up with message "No packages we pushed." But actually there was one package pushed.
Maybe it is because I have a matrix configuration under environment section, so AppVeyor runs deploy twice? If so, how can tell AppVeyor to deploy only once?
After some experiments, I found a fix, that is removing publish_nuget: true under build section. This line will cause AppVeyor to create a nuget package, and dotnet pack Src\App1.csproj command under after_build section will create a nuget package, too. So there will be two identical .nupkg files generated in different location, and AppVeyor will find both files and push them to nuget server.
Result:
build:
project: '%solution_name%'
after_build:
- dotnet pack Src\App1.csproj

How to use npm link command in Azure pipelines

I have created SPFX library module in which there is code to be shared with multiple webparts similar to the one here. I used npm link <lib name> command to link it. It works pretty well in the local environment as well as when I deploy it manually in SharePoint online app catalog. But if I deploy it using Azure Pipelines (YAML script) it always throws and error for library not found.
I have made it sure that the library is built first and then other webparts are built in pipeline (by introducting stages) but still it doesn't find the library. Is there a way to run npm link as a pipeline task?
If the library is first built in a different stage or job, the library will not be located in the same agent machine with the other webparts.
Let's say the library is built in Stage A and the other webparts are built in Stage B. As workaround, you will need to publish the library as artifacts to azure devops server using Publish Build Artifacts task in stage A. And then download the library to the agent which builds the other webparts in Stage B using Download Build Artifacts task.
For below example:
The library is built in stage A and published to azure devops server as artifacts named library.
In Stage B, the library artifacts is downloaded from azure devops server to folder $(Build.ArtifactStagingDirectory). Then you can refer to the library by path $(Build.ArtifactStagingDirectory)/library for the following tasks in Stage B.
If multiple webparts are built in different jobs in Stage B, each job in Stage B will need to download the library artifacts, for different jobs run on different agent virtual machines.
stages:
- stage: A
jobs:
- job: Library
pool:
vmImage: "windows-latest"
steps:
...
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: {path to the library}
ArtifactName: library
- stage: B
dependsOn: A
jobs:
- job: WebParts1
pool:
vmImage: "windows-latest"
steps:
- task: DownloadBuildArtifacts#0
inputs:
downloadPath: $(Build.ArtifactStagingDirectory)
buildType: current
artifactName: library
...
- job: WebParts2
pool:
vmImage: "windows-latest"
steps:
- task: DownloadBuildArtifacts#0
inputs:
downloadPath: $(Build.ArtifactStagingDirectory)
buildType: current
artifactName: library
...
After trying the solutions posted above it still didn't work so I published it as NPM package using npm publish command. This solved the problem.
We can also use this command in YAML to automatically publish the package everytime we build but that was not required in my case so I didn't use it.

How to stop azure dev ops yaml validation build from running for each branch?

We are using azure dev ops for CICD and validating PR's.
Yesterday I decided to start making yaml files for validation builds.
I created the pipeline. I set the branch policy for 'development' fine and the validation build ran okay.
However, something I see is that each time ANY branch gets a change to the files of the directory I've set the validation build for a build triggers.
So, let's say I've made a yaml pipeline(CI only) for project Main(src/Main) and i've set a branch policy on branch 'development' to trigger a validation build whenever there is a change to that Main folder(src/Main/*) with the Main.sln inside and it has been PR's from branch(i.e. feature/Main/FirstPR). This works, but then if i merge 'development' into any branch which has not had the change to the main directory it will trigger that build. No other branch policy includes validation for Main apart from development even if it has not been PR-ed, but simply pushed to.
Here is an example of the yaml file. Any feedback would be appreciated.
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
pool:
vmImage: 'windows-2019'
demands:
- msbuild
- visualstudio
- vstest
variables:
solution: 'src/Main/Main.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
inputs:
versionSpec: '5.0.0'
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'select'
vstsFeed: '5aaa76ac-3bqa-4567-usd9-btdse1c4c66a'
restoreDirectory: '../../packages'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Set;
# A pipeline with no trigger
trigger: none
On your validation build pipeline. This will stop the build being run regardless of which branch / paths have been pushed.
The validation build pipeline will still respect the branch policies you've setup for PRs.
You can then have something like;
paths:
include:
- 'src/ProjectA/*'
branches:
include:
- development
For your CI build pipelines which will trigger when there's a successful PR that affects ProjectA.

How to do dotnet publish in Build Yaml

Can you please give an example the way to specify in build.yaml if needs to do dotnet publish a test project in .Net Core 2.1. referred this couldn't figure out exactly the way.
It says below, what should be the yaml way
For this task to work, you must have already published the output of your build to this directory by using the dotnet publish --output $(Build.ArtifactStagingDirectory) command. To copy additional files to this directory before publishing,
As example how below represent in build.yaml in class application (API Solution)
dotnet publish ~/projects/app1/app1.csproj
Tried below
- task: DotNetCoreCLI#2
displayName: "Prepare Publish Files"
inputs:
command: publish
projects: ""
arguments: --output $(Build.ArtifactStagingDirectory)/src/xxx.EndToEnd.Integration.Tests/xxx.EndToEnd.Integration.Tests.csproj
But get below error, in fact mine is API solution where I am trying to publish end2end tests and run them after deployment.
##[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory.
##[error]Project file(s) matching the specified pattern were not found.
With below YAML code I was able to run the build
- task: DotNetCoreCLI#2
displayName: "dotnet e2e tests"
inputs:
command: publish
publishWebProjects: false
projects: '**/*.csproj'
arguments: --output $(Build.ArtifactStagingDirectory)/src/xxx.EndToEnd.Integration.Tests
zipAfterPublish: false
Explanation:
publishWebProjects: false - Since this is a API solution.
The easy way is to create task in designer wizard and see the YAML file there (Separate tab to show yaml file)

Resources