Azure DevOps Pipeline - Configure Unit Tests for UWP Project - azure

I'm pretty new to Azure DevOps and I am trying to get it to run the Unit tests (MSTest) as part of the pipeline. I'm using the default generated yaml for UWP. According to the documentation for unit tests I should have something like:
- task: VSTest#1
displayName: Unit tests
inputs:
testAssembly: '**/*test*.dll;-:**\obj\**
This is a high level of the file structure in question (relative to the yaml file):
Pipeline.yml
Project (folder)
Project.sln
ProjectDatabase (folder)
bin (folder)
obj (folder)
ProjectDatabase.csproj
ProjectDatabase.Test (folder)
bin (folder)
obj (folder)
ProjectDatabase.Text.csproj
ProjectDataAccess (folder)
bin (folder)
obj (folder)
ProjectDataAccess.csproj
ProjectDataAccess.Test (folder)
bin (folder)
obj (folder)
ProjectDataAccess.Test.csproj
Each time I've tried varying the path but running the Pipeline just returns:
##[warning]No test assemblies found matching the pattern: '**/**/*test*.dll;-:**\**\obj\**'.
Am I even going down the right path and if so, am I missing something? Thanks in advance and I greatly appreciate any assistance.

I was not thinking and ran the Unit Tests separately from the build itself so the appxrecipe files were not present.
To have the tests run I had to use:
- task: VSTest#2
displayName: Unit Tests
inputs:
platform: 'x64'
configuration: '$(BuildConfiguration)'
testSelector: 'TestAssemblies'
testAssemblyVer2: | # Required when testSelector == TestAssemblies
**\Release\ProjectName.UWP.Test.build.appxrecipe
**\Release\ProjectName.DataAccessUWP.Test.build.appxrecipe
**\Release\ProjectName.DataUWP.Test.build.appxrecipe
!**\*TestAdapter.dll
!**obj**
searchFolder: '$(Build.SourcesDirectory)'
resultsFolder: '$(System.DefaultWorkingDirectory)TestResults'

Related

I want to create a CICD for my azure repo which has multiple projects in its subfolders

My azure repo has multiple projects in it (it is not a single solution with multiple projects), which are placed in subfolders. How to publish artifacts separately for each of the project, which are placed in different folders.
By using paths include statements you can specify a build file and a trigger for each of the subdirectories.
An example below
trigger:
branches:
include:
- refs/heads/Development
paths:
include:
- slapi
- slapi.Common
batch: True
name: $(date:yyyyMMdd)$(rev:.r)
This allows each subdirectory to trigger and build to a separate output directory as needed.
In Azure Devops you then import this build YAML file to create your build pipeline and then when you create your release pipeline you select this build pipeline as the source for the drop files
Obviously you need to complete the above example file with the actual build configuration but since the question was about using subdirectories I included the relevant parts.
For your working directories use the variables section like this to specify the project at hand
variables:
vmImageName: "windows-2022"
workingDirectory: "projectName" <- change this to your real project name
then refer to the variables in your build task like this
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: "build"
projects: |
$(workingDirectory)/*.csproj
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release

How to register AutoIT COM DLL while running from azure

I am trying to use AutoIT in my automated tests for the project. Locally I am able to register the COM Library using regsvr32 but when I try to do the same from my azure pipeline, the script runs continuously.
I have my azure pipeline yml as following:
- job: Tests
displayName: Automated Tests
pool:
vmImage: "windows-latest"
steps:
- task: NuGetToolInstaller#1
- task: DotNetCoreCLI#2
displayName: Restore Packages
inputs:
command: 'restore'
projects: 'Free.Automation/Free.Automation.csproj'
feedsToUse: 'config'
nugetConfigPath: 'Free.Automation/nuget.config'
- task: BatchScript#1
displayName: Register AutoIT
inputs:
filename: 'Free.Automation/autoit.bat'
- task: MSBuild#1
inputs:
solution: "Free.Automation/Free.Automation.sln"
And this is the bat file I am using:
cd c:\windows\system32
regsvr32 C:\Users\%USERNAME%\.nuget\packages\autoitx.dotnet\3.3.14.5\build\AutoItX3.dll
I verified that the path of azure pipeline space is something D:\1\a\s but not sure how the directory works.
Could anyone help me registering the COM lib on azure hosted pipeline space?
With Azure DevOps Microsoft-hosted agent, you can't get your local files directly. So if you want to use COM DLLs, you need to include them in your source code files.
I recommend that you have a lib folder to store your DLLs in. Please make sure that your DLLs are referenced correctly as a relative path in .csproj.
I verified that the path of azure pipeline space is something D:\1\a\s but not sure how the directory works.
In Azure DevOps, you can use the predefined variable $(System.DefaultWorkingDirectory) to get the local path on the agent where your source code files are downloaded. That's the "azure pipeline space D:\1\a\s" you mentioned.

What's should I specify for the rootDirectory of an Azure Pipeline for a static website?

I manage a static website. No database, no server-side processing like ASP.NET (IIS), PHP, etc. This website is comprised of just HTML, CSS, some JavaScript, and a few graphic files. I'm trying to use Azure Pipelines for this. This is my first time using Azure Pipelines. I chose an HTML template to start the YAML pipeline.
I'm using the FTP Upload task. The source code is in Azure DevOps Repos. I'm testing the Pipeline by trying to FTP the files to a test folder on the hosting server (not a part of Azure). In testing the pipeline, I get this error:
##[error]Error: Failed find: ENOENT: no such file or directory, stat '/bin/pyvenv'
I don't know what I should put as the rootDirectory. I thought it appropriate to put the "/". Here's the YAML:
# HTML
# Archive your static HTML project and save it with the build record.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- none
pool:
vmImage: 'ubuntu-latest'
steps:
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(build.sourcesDirectory)'
includeRootFolder: false
- task: FtpUpload#2
inputs:
credentialsOption: 'inputs'
serverUrl: 'ftp://ftp.destination.com'
username: '$(TheUsername)'
password: '$(ThePassword)'
rootDirectory: '/'
filePatterns: '**'
remoteDirectory: '/test'
clean: false
cleanContents: false
preservePaths: false
trustSSL: false
What should I put for the rootDirectory?
Have you tried
rootDirectory: '.'
OR
rootDirectory: '$(Pipeline.Workspace)' ?
The task ArchiveFiles field archiveFile default value is $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip.
According to your YAML build definition, you have archived the folder $(build.sourcesDirectory) to the path $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip, and next task is FtpUpload, then field rootDirectory should be $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip and it will upload the zip file to a remote machine.
If you want to upload the static website, you could also set the field rootDirectory to $(Build.SourcesDirectory). Check the doc build variables for more details.
The root directory is your source code directory from where your compiled code is, in your case it should be checkout path.
I think you should use should use $(System.DefaultWorkingDirectory)/rootFolderName.
Here root folder should be your repo name. You try printing the content of the $(System.DefaultWorkingDirectory) to check whether you need to use $(System.DefaultWorkingDirectory) only or any nested folder inside it.

What path should I point the AzureWebApp task to?

I'm trying to deploy a react web app. Here is my current yaml file. I've been following this tutorial.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
azureSubscription: <myServiceConnection>
appName: <myAppName>
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
#so this calls the build object in package.json. Theoretically creates a /build/ directory
- script: |
npm install
npm run build
displayName: 'npm install and build'
#this should copy contents of build into artifactstagingdirectory.
- 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
- task: AzureWebApp#1
inputs:
azureSubscription: <myServiceConnection>
appName: <myAppName>
appType: webAppLinux
package: $(Build.ArtifactStagingDirectory)/**/www/build
customWebConfig: '-handler iisnode -NodeStartFile server.js -appType node'
Basically, the issue is that I dont understand where the PublishBuildArtifact task publishes the files, and so I don't know where to point the package of AzureWebApp to.
So I turned on system.debug and I got the following information
npm install build uses the following directory: /home/vsts/work/1/s
copy files copies the build folder over. So it goes /home/vsts/work/1/s/build to /home/vsts/work/1/a/build. So this means artifactstagingdirectory is /home/vsts/work/1/a
Publish Build artifacts takes the artifactstagingdirectory and publishes it to some folder www/build. The following output is provided: Upload '/home/vsts/work/1/a' to file container: '#/8995596/www'
The current AzureWebApp task is looking in /home/vsts/work/1/a/**/www/build
So I think it should be the right directory. However, it is not providing the whole path in step 3. So it looks like I'm wrong. Where is this www folder being created?
Also since it doesn't seem like building/publishing the react app will create a zip file, do I just point it to the build folder or the www folder?
try
**/wwwroot/
instead of **/www/
Check following blog from Microsoft with deployment details outlined.
https://learn.microsoft.com/en-us/azure/app-service/faq-deployment

Gitlab Pages throw 404 when accessed

I have a group project with the following name (hosted in Gitlab): gitlab.com/my-group/my-project.
I have generated coverage reports during testing and saved them as artifacts using Gitlab CI. Here is Gitlab CI config:
test:
stage: test
image: node:11
before_script:
- npm install -g yarn
- yarn
cache:
paths:
- node_modules/
script:
- yarn lint
- yarn test --all --coverage src/
except:
- tags
artifacts:
paths:
- coverage/
coverage: '/Statements\s+\:\s+(\d+\.\d+)%/'
deploy-pages:
stage: deploy
dependencies:
- test
script:
- mv coverage/ public/
artifacts:
paths:
- public/
expire_in: 30 days
except:
- tags
When I open deploy stage job, I can see the artifact being created. Here is the screenshot: . All the files are under /public directory in the artifact.
Now, when I go to: https://my-group.gitlab.io/my-project, I keep getting 404.
I am not sure what step I am missing here. Can someone shed some light on this issue for me?
Thanks!
There are three basic requirements for the project itself:
project must be named group.gitlab.io (if you want it to be the base domain)
job must create artifact in public directory
job must be called pages
Most likely it's the last one that needs fixing since your job is currently called deploy-pages. Simply rename that to pages.
You'll know when you got everything working because under Settings > Pages, it will tell you the link where it's published to.

Resources