Azure DevOps Release Pipeline - Protractor UI tests suite - azure

I am being tasked to work on Azure DevOps implementation of an existing legacy application. Application has a QA team which uses 500+ automated test cases. This test cases have been developed using Protractor.
All test cases are developed using JavaScript.
With Existing setup, below are the steps taken:
a. release pipeline deploys an ASP.NET application to Azure app services
b. QA person manually logs on to the VM and initiates the protractor tests.
Can we use any tasks from Azure devOps pipeline to test the same deployed application?

Can we use any tasks from Azure devOps pipeline to test the same deployed application?
To run the test with Protractor, you can use the Command Line task with node tool to run the test.
If you want to use the Microsoft-hosted agent to run the test, you need to install the appropriate version of the node tool and protractor package before running the test.
Here is an example:
steps:
- task: NodeTool#0
displayName: 'Use Node 10.x'
inputs:
versionSpec: 10.x
- task: Npm#1
displayName: 'npm install'
inputs:
workingDir: EndToEndTests/EndToEndTests
verbose: false
- script: 'node $(build.sourcesdirectory)/EndToEndTests/EndToEndTests/node_modules/protractor/bin/webdriver-manager update --versions.chrome=xxxx.x.x.x'
displayName: 'Command Line Script'
- script: |
npm run e2e #Run the same script as you are on the VM
displayName: 'Command Line Script'
For more detaield info, you could refer to this blog or this ticket .
On the other hand, if your test cases requires more additional configuration, you can also install a self-hosted agent on the VM.
In this case, the QA person don't need to log on the VM. They could directly run the Pipeline tasks on the self-hosted agent(create on the VM). This is equivalent to testing on the VM.

Related

Node Express Webpack API Release to Azure Dev Ops

I'm trying to release my project using Nodejs Express on Azure Dev Ops and Deploy on Release, but when I try to open the link. I'm getting a "The page cannot be displayed because an internal server error has occurred." error.
YAML:
pool:
name: Azure Pipelines
steps:
task: NodeTool#0
displayName: 'Use Node 14.x'
inputs:
versionSpec: 14.x
task: Npm#1
displayName: 'npm install'
inputs:
verbose: false
task: Npm#1
displayName: 'npm custom'
inputs:
command: custom
verbose: false
customCommand: 'run build'
task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)'
Package Script
Webpack.config
and on Azure Pipeline
the default setting of npm install and build
and on Azure Release
All are working fine, on the build and release.
Blank Page
I'm starting to guess the problem was from the azure portal, or on the way it was setup. Because I didn't create the portal. I'm only the Contributor.
Please help clarify this.
I try to build all files on SCM \wwwroot
Make sure the index.js file is deployed to your azure app service
As you have some issues with your existing application Create the new application using this MS-DOC
Sign into Azure Pipelines. Your browser will go to to display your Azure DevOps dashboard.
Create New pipeline under the pipeline's menu of your project
Select GitHub as the source code location.
If the code is placed in GitHub, then login with Git Creds
When the list of repositories appears, select your sample Node.js repository.
Azure Pipelines analyzes the code in your repository and automatically gives a Node.js template for your pipeline. Select this template.
Azure Pipelines will automatically generates a YAML file in your pipeline. Click on Save and Run > Commit Directly to Master Branch and then choose Save ad Run again.
A new run begins. Wait for the run to complete.
The link is used to create a pipeline is azure devops Deploying a Node JS App to Azure App Service using Azure Dev-ops (Part 1)
The link will be used to deploy the Nodejs app to Azure portal using azure pipelines Deploying a Node JS App to Azure App Service using Azure Dev-ops (Part 2)
This error is a common description of the IIS server error 500. It will be difficult to find the root cause of the question with just a general description.
For more details, please Reference the SO-Thread

Why is test automation only partially successful with Cypress and Azure DevOps?

I am using Cypress.io (Version 5.1.0) for testing my project.
My project is in azure DevOps. Now i want to include my cypress tests in Azure DevOps so my tests will run automatically.
I set up the JUnit reporter on my Cypress project:
into my “package.json” file i added
"cypress-multi-reporters": "^1.2.4",
"mocha-junit-reporter": "^1.23.3"
then run
npm install
than added
"scripts": {
"scripts": "cypress run",
"test": "npm run scripts"
}
Into my “cypress.json” file i added
"reporter": "mocha-junit-reporter",
"reporterOptions": {
"mochaFile": "cypress/reports/junit/test-results.[hash].xml",
"testsuitesTitle": false
}
After this I created a new Pipeline using Azure Repos in Azure DevOps.
For Pipeline Configuration i selected Node.js.
Now I have a YAML file. Here i removed npm build from the first script.
Now I picked npm from the assisstant. On the npm configurations, I selected custom and write the command run test . Now I Select the result format as “JUnit” and set Test results files to “*.xml”
At last I selected the option "Merge test results".
Now I saved and run the pipeline.
This is what my Job does:
Pool: Azure Pipelines
Image: ubuntu-latest
Agent: Hosted Agent
Started: Yesterday at 17:31
Expanded: Object
Result: True
Evaluating: not(containsValue(job['steps']['*']['task']['id'], '6d15af64-176c-496d-b583-fd2ae21d4df4'))
Expanded: not(containsValue(Object, '6d15af64-176c-496d-b583-fd2ae21d4df4'))
Result: True
Evaluating: resources['repositories']['self']['checkoutOptions']
Result: Object
Finished evaluating template 'system-pre-steps.yml'
********************************************************************************
Template and static variable resolution complete. Final runtime YAML document:
steps:
- task: 6d15af64-176c-496d-b583-fd2ae21d4df4#1
inputs:
repository: self
MaxConcurrency: 0
What is wrong with my automation? How can I fix this?
Update:
Thats my yml file:
# Node.js
# Build a general Node.js project with npm.
# 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
displayName: 'npm install'
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'run test'
continueOnError: true
- task: PublishTestResults#2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/cypress/reports/junit'
mergeTestResults: true
testRunTitle: 'Publish Test Results'
I got an email with this Details
Job 1 error(s), 1 warning(s) Error: Npm failed with return code: 254
The issue may be due to the agent rather than your code and scripts.
You can try the following solutions:
Change your agent image. As you are currently using the ubuntu-latest, it is recommanded to try the ubuntu-20.04 or ubuntu-16.04.
Use a self-hosted agent. If you don't have a self-hosted agent, click Self-hosted Linux agent for detailed steps.
Change the orgnization. Choose another organization that can run the build correctly, and just in case, it is better to create a new organization. Then create a new project and try your tests.
As stated already, the problem most likely lies with the Azure environment. Cypress has a dependency on a browser (electron, chrome) in order to execute. For example, if you are using docker, they provide an official image called cypress/browsers:node14.7.0-chrome84 that has everything you need out of the box. The Dockerfile also has useful info on the environment needed. Make sure to provide a headless configuration as well, something like:
cypress run --headless --browser chrome --spec yourSpecHere.js

How to set up build and release pipeline for NestJS application to Azure using YAML

I am having trouble understanding and getting the build/release pipelines setup for deploying a NestJS application to Azure DevOps (ADO).
I am deploying to a Linux Web App hosted in Azure.
As far as I understand, if I run the app locally using something like npm run start, it creates a dist folder under my root project directory.
So, when writing the YAML for the build and deployment. My thought process is to:
Run an NPM update.
Run npm run build to build the application and generate the dist folder.
Copy the contents of the application (or just the dist folder?) into the target folder (/home/site/wwwroot)
Run npm run start:prod to start the server.
Here is my YAML so far:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseNode#1
inputs:
version: '14.x'
checkLatest: true
- task: Npm#0
displayName: Run NPM Update for NestJS
inputs:
cwd: '$(Build.SourcesDirectory)/ProjectName'
command: update
- task: Npm#0
displayName: Build NestJS
inputs:
cwd: '$(Build.SourcesDirectory)/ProjectName'
command: run
arguments: "build"
- task: CopyFiles#2
inputs:
Contents: 'dist/**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
The issue is after the build process completes, I do not see a dist folder in /home/site/wwwroot/ProjectName. Can someone help me out with what I am missing?
Also, a side noob-y question about Azure DevOps, what does $(Build.SourcesDirectory) and $(Build.ArtifactStagingDirectory) refer to and how and where are those environment variables set?
To deploy your app to the hosted in Azure. You need to use Azure App Service Deploy task or Azure Web App task.
Azure devops is the tool to build and deploy your app to your server(eg. the Linux Web App on Azure), it is not for hosting your app.
$(Build.ArtifactStagingDirectory) refer to the folder of the agent machine which runs your pipeline. (When your run your pipeline, it pick up a agent defined in pool to run your pipeline tasks)
The mapping to the folders in the agent machine is showing as below screenshot. Check the predefined variables for more information.
$(Agent.BuildDirectory) is mapped to c:\agent_work\1
$(Build.ArtifactStagingDirectory) is mapped to c:\agent_work\1\a
$(Build.BinariesDirectory) is mapped to c:\agent_work\1\b
$(Build.SourcesDirectory) is mapped to c:\agent_work\1\s
So back to the question how to deploying a NestJS application to Azure?
First you need to create a service connection in Azure devops to connect to your azure subscription. Check here for detailed steps.
Then add Azure App Service Deploy task/Azure Web App task to the end of your pipeline. See below example:
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'SubscriptionServiceConnectionName'
appType: 'webAppLinux'
WebAppName: 'MyWebAppName'
Package: '$(Build.ArtifactStagingDirectory)/dist/'
StartupCommand: 'npm run start:prod'
You can check here for more information.

Simple Appium test in Azure Pipeline - how do I fix the failing build step (vstest)?

Given:
Appium Windows Application Driver
Visual Studio 2019 solution
WPF Project .Net 4.7.2
Unit Test MSTest .Net 4.7.2
Azure DevOps Pipelines
I have a minimalist solution with a WPF project that just has a label "Hello World." In the unit test project I'm using Appium to test the existence of Hello World. Very simple and runs successfully locally.
However, when I put in build in Azure DevOps my one and only test fails and I can't figure out why.
Here's the Microsoft documentation that says Microsoft hosted agents are preconfigured to run Appium Tests.
Here's a link to my Azure DevOps
Below error is abstracted from the vstest task log. It seems the WinAppDriver didnot startup correctly in the hosted agent.
OpenQA.Selenium.WebDriverException: OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server --->
...
at UnitTestProject1.WpfAppSession.Setup() in d:\a\1\s\RsSolution6\UnitTestProject1\WpfAppSession.cs:line 31
at UnitTestProject1.UnitTest1.ClassInitialize(TestContext context) in d:\a\1\s\RsSolution6\UnitTestProject1\UnitTest1.cs:line 20
There's now a dedicated WinAppDriver Pipelines Task available on the Azure Marketplace to help you easily enable and configure WinAppDriver from inside your DevOps Pipeline. See
WinAppDriver in CI with Azure Pipelines.
Install WinAppDriver task to your organization, and add it in your pipeline to start and stop winappdriver.
- task: Windows Application Driver#0
inputs:
OperationType: Start
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: Windows Application Driver#0
inputs:
OperationType: Stop

azure DevOps pipeline CI/CD

I am using an Open-Source project Magda (https://magda.io/docs/building-and-running) and want to make an Azure CI/CD Pipeline.
For this project, there are some prerequisites like having sbt + yarn + docker + java installed.
How can I specify those requirements in the azure-pipelines.yml file.
Is it possible in azure-pipelines.yml file, to just write scripts? Without any use of jobs or tasks? And what's the difference between them (Tasks,Jobs ... )
(I'm currently starting with it, so I don't have much experience)
That's my current azure-pipelines.yml file (if there is something wrong please tell me)
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- release
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.0.0'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- script: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
displayName: 'install Helm '
- script: |
yarn global add lerna
yarn global add #gov.au/pancake
yarn install
displayName: 'install lerna & pancake packages'
- script: |
export NODE_OPTIONS=--max-old-space-size=8192
displayName: 'set Env Variable '
- script: |
lerna run build --stream --concurrency=1 --include-dependencies
lerna run docker-build-local --stream --concurrency=4 --include-filtered-dependencies
displayName: 'Build lerna '
I recommend you read this Key concepts for new Azure Pipelines users
It is possible to put all your stuff in one script step, but now you have logical separation, and this helps navigate and read file than one really long step.
Here you have some bascis from above mentioned documentation:
A trigger tells a Pipeline to run.
A pipeline is made up of one or more stages. A pipeline can deploy to one or more environments.
A stage is a way of organizing jobs in a pipeline and each stage can have one or more jobs.
Each job runs on one agent. A job can also be agentless.
Each agent runs a job that contains one or more steps.
A step can be a task or script and is the smallest building block of a pipeline.
A task is a pre-packaged script that performs an action, such as invoking a REST API or publishing a build artifact.
An artifact is a collection of files or packages published by a run.
But I really recommend you to go through it.
For this project , there are some prerequisites like having sbt + yarn + docker + java installed. How can i specifiy those requirements in the azure-pipelines.yml file.
If you are using Microsoft hosted agents you cannot specify demands
Demands and capabilities apply only to self-hosted agents. When using Microsoft-hosted agents, you select an image for the hosted agent. You cannot use capabilities with hosted agents.
So if you need sth what is not inside the agent you can install it and use taht new piece of sfotware. Later when you job is finished agent is restroed to original version. If you go for self hosted agent you can specify demands and based on agents capabilities it can be assigned to your job.

Resources