in

How do I add Jmeter tests to a Jenkins scripted pipeline for a .Net Core Project


I have a Jenkins pipeline for .Net Core REST API and I would like to add a stage for ‘Perfomance Test’ using JMeter. I cannot seem to find a concrete example that utilises a .Net Core based project.

Ideally I want the stage to execute tests for metrics like response time, throughput, CPU/Memory usage, and how many concurrent users the API can handle. I would want to be able to then view the reports in Build Artifacts after the pipeline ends.

This is my pipeline (with a sample stage I think I can improve):

pipeline {
agent any
triggers {
    githubPush()
}
environment { 


 NAME = "cassavagateway"
   REGISTRYUSERNAME = "golide"
   WORKSPACE = "/var/lib/jenkins/workspace/OnlineRemit_main"
   VERSION = "${env.BUILD_ID}-${env.GIT_COMMIT}"
   IMAGE = "${NAME}:${VERSION}"
}
    stages {
        stage('Restore'){
           steps{
               sh 'dotnet restore OnlineRemit.sln'
            }
         }
        stage('Clean'){
           steps{
               sh 'dotnet clean OnlineRemit.sln --configuration Release'
            }
         }
        stage('Build'){
           steps{
               sh 'dotnet build OnlineRemit.sln --configuration Release --no-restore'
            }
         }
           stage('Unit Test'){
           steps{
               sh 'dotnet test --logger "trx;LogFileName=TestResults.trx"  --logger "xunit;LogFileName=TestResults.xml" --results-directory ./BuildReports/UnitTests /p:CollectCoverage=true /p:CoverletOutput=BuildReports/Coverage/ /p:CoverletOutputFormat=cobertura /p:Exclude="[xunit.*]*"'
               sh 'dotnet ~/.nuget/packages/reportgenerator/4.8.13/tools/net5.0/ReportGenerator.dll "-reports:/var/lib/jenkins/workspace/OnlineRemit_main/IntegrationTests/BuildReports/Coverage/coverage.cobertura.xml" "-targetdir:/var/lib/jenkins/workspace/OnlineRemit_main/IntegrationTests/BuildReports/Coverage" "-reporttypes:HTML;HTMLSummary"'
            }
         }  
         stage ("Publish Test Report") {
             steps{               
                     publishHTML target: [
      allowMissing: false,
      alwaysLinkToLastBuild: true,
      keepAll: true,
      reportDir: '/var/lib/jenkins/workspace/OnlineRemit_main/IntegrationTests/BuildReports/Coverage',
      reportFiles: 'index.html',
      reportName: 'Code Coverage'
      ]
               archiveArtifacts artifacts: 'IntegrationTests/BuildReports/Coverage/*.*'
               }
         }
 stage ("Perfomance Test") {
             steps{               
            dir("${WORKSPACE}/scripts") {
            sh 'my_jmeter_install_path_here/apache-jmeter/apache-jmeter/bin/jmeter.bat -n -t Shift-Left.jmx -l Shift-Left.jtl'
            //Is this correct ? Which commands do I put here ? Which directory do I point to
            }
               archiveArtifacts artifacts: //what do i put here
               }
         }       
         stage ("Docker Build") {
            steps {
               sh  'cd /var/lib/jenkins/workspace/OnlineRemit_main/OnlineRemit'
               echo "Running ${VERSION} on ${env.JENKINS_URL}"              
               sh "docker build -t ${NAME} /var/lib/jenkins/workspace/OnlineRemit_main/OnlineRemit"
               sh "docker tag ${NAME}:latest ${REGISTRYUSERNAME}/${NAME}:${VERSION}"
               
            }
         }

         stage("Deploy To K8S"){
        sh 'kubectl apply -f {yaml file name}.yaml'
        sh 'kubectl set image deployments/{deploymentName} {container name given in deployment yaml file}={dockerId}/{projectName}:${BUILD_NUMBER}'
  }
      }

}
 

My issues :
What commands should i use for the actual test, I understand they should be an existing .jtl file but I am not sure why this is actually needed , how I generate it and where it should be located. I do intend to install Jmeter on the Jenkins server for this.

How do I archive the results of the test so that I can access them in the Jenkins UI.

How can I incorporate a condition to break the pipeline if the tests fail.

Jenkins Environment : Debian 10
Platform : .Net Core 3.1



Source: https://stackoverflow.com/questions/70607946/how-do-i-add-jmeter-tests-to-a-jenkins-scripted-pipeline-for-a-net-core-project

Apple Mixed Reality Headset Will Have Limited Supply

Beezly.io — Business plans and company analysis creator