I am attempting to create a gitlab CI/CD pipeline that includes automated Cypress tests on a .NETcore project. I have a collection of cypress tests that I can successfully run locally. They are stored in the directory:
<project>/Cypress/integration/
My Gitlab CI/CD pipeline is successfully deploying and building the
code on my testing server (Windows Server 2012). However, after deployment the cypress folder is not present on my testing server. However, when I build the project locally there is a cypress folder. In both my local build and the build defined by the gitlab-ci.yaml, the build command is the same:
dotnet publish -c Release
That said, during local builds, the content in my /bin/Release/netcoreapp2.1.publish/cypress does not include my locally created tests- just the examples provided by cypress. The restoring of the node packages is obviously creating a new cypress install.
How can I get my local cypress tests onto my testing server? Any why does the build done via Gitlab CI/CD and my local build differ in whether cypress gets installed?
I have tried updating my .csproj file to include the cypress directory in the build like so:
<ItemGroup>
<!-- include cypress tests in build for automated testing-->
<Content Include="cypress\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
But this gives me an error:
... error NETSDK1022: Duplicate 'Content' items were included...
Any suggestions on how to get this working? Below I am including my gitlab-ci.yaml file:
stages:
- build
- test
- deploy
build:
stage: build
tags:
- cris .netcore
script:
- echo "removing old files"
- 'Remove-Item -path D:\DeployedWebApps\cris-automated-tst\* -recurse'
- echo "dotnet build started"
- 'dotnet publish -c Release -o "D:\DeployedWebApps\cris-automated-tst\"'
test:
stage: test
tags:
- cris .netcore
script:
- echo "testing"
- 'npx cypress run'
deploy:
stage: deploy
tags:
- cris .netcore
script:
- echo "deploying"
when: on_success
environment:
name: Development
url: https://cris-automated-tst.gisdata.mn.gov
only:
- dev
Looks like I solved this on my own. The trick was to publish just the Cypress Integration folder rather than the whole Cypress directory:
<ItemGroup>
<!-- include cypress tests in build for automated testing-->
<Content Include="cypress\integration\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Related
Problem: A variety of tutorials from AWS for integrating automated testing with CI/CD look to integrate the testing stage after, or within the build process by using a localhost:3000 server.
However, as AWS Amplify developers know, the local environment can sometimes offer a different user experience to deploying to a development environment, and using that environment with AWS Amplify's hosting service.
Therefore, how do I add testing not only at the build stage with localhost:3000, but also for the development environment's hosted url?
I'm looking to build all my resources (backend and front-end), with a git push to the code commit repository.
Idea of Stages:
Source
Build
Test
Deploy Cloud Formation Stacks
Test
Roll back if failure
Current amplify.yml:
Note: this currently does not work so please do not copy it for your build. Please refer to the hyperlink above.
version: 0.2
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
test:
phases:
preTest:
commands:
- npm ci
- npm install wait-on
- npm install pm2
- npm install mocha mochawesome mochawesome-merge mochawesome-report-generator
- npx pm2 start npm -- dev
- 'npx wait-on --timeout 300 http://localhost:3000'
test:
commands:
- 'npx cypress run --reporter mochawesome --reporter-options "reportDir=cypress/report/mochawesome-report,overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss"'
postTest:
commands:
- npx mochawesome-merge cypress/report/mochawesome-report/mochawesome*.json > cypress/report/mochawesome.json
- npx pm2 kill
artifacts:
baseDirectory: cypress
configFilePath: '**/mochawesome.json'
files:
- '**/*.png'
- '**/*.mp4'
I have a dotnet core app I am trying to deploy to Azure with GitHub actions CI/CD. However, the app is not on root repository but rather inside of another folder MYAPP. So I had to update working-directory of build and publish jobs but now I keep getting this error:
Run azure/webapps-deploy#v2
Error: Deployment Failed with Error: Error: No package found with specified pattern: ./published
My project structure is as such
├── .github/workflows
├── MYAPP
├───── MYAPP.sln
├───── MYAPPTESTS
├───── MYAPP
├─────────── MYAPP.csproj
├── docs
├── OtherFolder
└── README.md
My YML file is as below
name: Build and deploy ASP.Net Core app to Azure Web App - myappdeploy
on:
push:
branches:
- main
workflow_dispatch:
env:
AZURE_WEBAPP_PACKAGE_PATH: './published'
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- name: dotnet build and publish
working-directory: ./MYAPP
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release -o ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy#v2
with:
app-name: 'myappdeploy'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_7894EB5E4C174F72A5EDE9C64B658907 }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
What am I missing?
Thanks
Instead of working directory I have tried adding .deployment to root repository.
[config]
project = ./MYAPP
However this file was not read and the pipeline would say that it can't find .sln file. I have also tried adding Project app setting on Azure App Service configuration but still the pipeline would not work.
I have tried removing the package parameter of the azure/webapps-deploy#v2 and the pipeline runs successfully however I instead get the error when accessing the website:
You do not have permission to view this directory or page
Also, none of the routes of my app can be found (404)
When running the solution locally there are no issues.. and when deploying manually to an app service through Visual Studio GUI there are also no issues. However, this is not a proper solution as GitHub CI/CD is needed.
For anyone who might come into the same issue, I had to specify where the .sln is during dotnet build and where the .csproj is for dotnet publish. Also remove working-directory
- name: dotnet build and publish
# working-directory: ./MYAPP
run: |
dotnet restore
dotnet build MYAPP/MYAPP.sln --configuration Release
dotnet publish MYAPP/MYAPP/MYAPP.csproj -c Release -o ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
I'm facing trouble with my GitLab CI. The expected workflow for my Test stage is :
fetching changes
checking out
downloading artifacts
run dotnet test
uploading artifacts
The current workflow is :
fetching changes
checking out (removing all bin/obj folder)
uploading artifacts -> this line failed due to inexistance of my test-results.xml file
My solution looks like this:
-- yml file
-- MyApp
-- MyApp.Tests
The version of my gitlab-runner is 12.4.1 and I'm using the shell executor on Windows environment.
Please find below my yml file:
image: mcr.microsoft.com/dotnet/core/sdk:3.1
variables:
EXE_RELEASE_FOLDER: 'Oncolin.UI.Desktop\bin\Release'
# the folder inside the deploy folder
DEPLOY_FOLDER_APP: 'Oncolin.UI.Desktop\Builds'
CONFIGURATION: 'release'
#NUGET_PATH: 'C:\NuGet\nuget.exe'
#MSBUILD_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe'
#MSTEST_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\MSTest.exe'
NUNIT_PATH: '.\packages\NUnit.ConsoleRunner.3.9.0\tools\nunit3-console.exe'
SOLUTION: 'Oncolin.sln'
stages:
- build
- test
build:
stage: build
tags:
- windows
script:
- '& nuget restore' # restore Nuget dependencies
- '& dotnet restore'
- '& SonarScanner.MSBuild.exe begin /k:Oncolin /d:sonar.host.url=https://docker:10500 '
- '& dotnet build -c release'
- '& "$env:MSBUILD_PATH" "$env:SOLUTION" /t:Build /p:Configuration=Release' # build the project
- '& SonarScanner.MSBuild.exe end'
artifacts:
expire_in: 1 week # save gitlab server space, we copy the files we need to deploy folder later on
paths:
- '$env:EXE_RELEASE_FOLDER\*' # saving exe to copy to deploy folder
- 'RNC.RULES.QUALITY.TESTS\*' # saving entire Test project so NUnit can run tests
- 'RNC.MODEL.TNM.TESTS\*' # saving entire Test project so NUnit can run tests
- 'Oncolin.Model.Tests\*' # saving entire Test project so NUnit can run tests
test:
stage: test
tags:
- windows
allow_failure: false
script:
- '& dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=$CI_PROJECT_DIR\artifacts\{assembly}-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"'
artifacts:
expire_in: 1 week # save gitlab server space, we copy the files we need to deploy folder later on
when: always
paths:
- $CI_PROJECT_DIR\artifacts\*test-result.xml
reports:
junit:
- $CI_PROJECT_DIR\artifacts\*test-result.xml
dependencies:
- build
Can someone explain to me why the downloading and dotnet test steps are skipped ? I hope I gave enough informations.
Thanks in advance.
The issue came from the sonar scanner. Even if I used the .Net Core sonar scanner, I had the same issue during my test stage.
I don't know why and I have already lost too many time to investigate on that.
I resolved it by creating a new stage specificly to run the sonar and ran it after the test stage.
I am new to CI and tried to add the following yaml to our project.
image: microsoft/dotnet:latest
stages:
- test
test:
stage: test
before_script:
- 'echo Stage - Test started'
- 'dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools'
script:
- 'cd "./My Project"'
- 'dotnet test --settings:./Settings/CodeCoverage.runsettings --collect:"XPlat Code Coverage"'
- './tools/reportgenerator "-reports:./Tests/*/TestResults/*/coverage.cobertura.xml" "-targetdir:Reports_Coverage" -reportTypes:TextSummary'
- 'cat ./Reports_Coverage/Summary.txt'
after_script:
- 'echo Stage - Test finished'
On the job I get the following output:
Running with gitlab-runner 13.7.0 (943fc252) on ***
Resolving secrets
Preparing the "kubernetes" executor
Using Kubernetes namespace: gitlab-pipeline
Using Kubernetes executor with image microsoft/dotnet:latest ...
Preparing environment
Running on*** via ***...
Getting source from Git repository
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/***/.git/
Created fresh repository.
Checking out 07e98444 as ***...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ echo Stage - Test started
Stage - Test started
$ dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
You can invoke the tool using the following command: reportgenerator
Tool 'dotnet-reportgenerator-globaltool' (version '4.8.4') was successfully installed.
$ cd "./My Project"
$ dotnet test --settings:./Settings/CodeCoverage.runsettings --collect:"XPlat Code Coverage"
Running after_script
Running after script...
$ echo Stage - Test finished
Stage - Test finished
Cleaning up file based variables
ERROR: Job failed: command terminated with exit code 1
I tinkered around a little bit and realized, that this minified yaml also fails:
image: microsoft/dotnet:latest
stages:
- test
test:
stage: test
before_script:
- 'cd "./My Project"'
- 'dotnet restore'
script:
- 'dotnet test --no-restore'
This generates an equal output, except it stops at dotnet restore.
I honestly don't know what to do, since this is the most minified version of a test I found.
Did I mess up something within the project, or is the problem within the GitLab Runner itself?
Project Version: .net Core App 3.1
Not a real solution, but I found the issue behind this. You can set the verbosity level of the dotnet test command (documentation). While doing so, I found out that you obviously cannot run a WPF project within a Linux based GitLab Runner.
Have a yaml file build script and all works fine except for the unit test which fails after various warnings eventually raising MSB3027 and MSB3021 errors.
This is in a pipeline in Atlassian.
Seen issues mentioning long PATH names but how to resolve here? Have similar pipelines setup and working before.
image: mcr.microsoft.com/dotnet/core/sdk:3.1
pipelines:
branches:
develop:
- step:
name: Build and Test
caches:
- dotnetcore
script:
- export ENV_NAME=develop
- export PROJECT_NAME=Myapi
- export ZIP_FILE=Myapi-dev.zip
- export TEST_PROJECT=Myapi.Tests
- dotnet build $PROJECT_NAME
- dotnet test $TEST_PROJECT --no-build --configuration Release
# this will publish our app output into a subfolder so that we can package it up
- dotnet publish $PROJECT_NAME --output $ENV_NAME/publish --configuration release
/usr/share/dotnet/sdk/3.1.402/Microsoft.Common.CurrentVersion.targets(4364,5):
warning MSB3026: Could not copy "/root/.nuget/packages/microsoft.testplatform.objectmodel/16.7.1/lib/netstandard2.0/pt-BR/Microsoft.TestPlatform.CoreUtilities.resources.dll"
to "bin/Release/netcoreapp3.1/pt-BR/Microsoft.TestPlatform.CoreUtilities.resources.dll". Beginning retry 1 in 1000ms.
Could not find a part of the path '/opt/atlassian/pipelines/agent/build/myapi/bin/Release/netcoreapp3.1/pt-BR/Microsoft.TestPlatform.CoreUtilities.resources.dll'.
In the end this was a third party component and the resource file the Test project needed was not in the expected location for the build pipeline. I worked around the issue by copying the files it needed into the target location.
# Workaround for resource file case sensitivity issue
- ls -lR .
- cp -R ./Myapi/bin ./Myapi.Tests/bin
- cp -R ./Myapi/bin/Debug/netcoreapp3.1/pt-br ./Myapi.Tests/bin/Debug/netcoreapp3.1/pt-BR
- dotnet test $TEST_PROJECT