Running jmeter tests in jenkinsfile - jenkins

I'm trying to run some jmeter tests in my jenkinsfile pipeline, but I'm getting some errors.
A problem was found with the configuration of task ':jmReport' (type 'TaskJMReports').
- In plugin 'net.foragerr.jmeter' type 'net.foragerr.jmeter.gradle.plugins.TaskJMReports' property 'reportDir' is missing an input or output annotation.
This is how I'm trying to run it.
build.gradle
plugins {
id "net.foragerr.jmeter" version "1.0.5-2.13"
}
apply plugin: 'net.foragerr.jmeter'
jmeter {
jmTestFiles = [file("src/test/jmeter/TestPlan.jmx")]
enableExtendedReports = true //produce Graphical and CSV reports
}
Pipeline
stage('Run Non-Functional tests - Windows'){
when { expression { env.OS == 'BAT' }}
steps {
dir('') {
bat 'gradlew.bat jmReport'
}
}
}
I'm also tried this away.
build.gradle
plugins {
id "de.qualersoft.jmeter" version "2.1.0"
}
tasks.register('jmRun',JMeterRunTask) {
jmxFile.set("TestPlan.jmx")
}
tasks.register("jmReport",JMeterReportTask) {
jmxFile.set("TestPlan.jmx")
dependsOn("jmRun")
deleteResults=true
}
The stage is the same and I'm getting this error.
> Could not get unknown property 'JMeterRunTask' for root project 'flowcrmtutorial' of type org.gradle.api.Project.
Why am I getting this errors?

For the latter, you are missing the import as stated in the project's README:
https://github.com/qualersoft/jmeter-gradle-plugin#user-content-running-a-jmeter-test
Import task package.
import de.qualersoft.jmeter.gradleplugin.task.*
plugins {
id "de.qualersoft.jmeter" version "2.1.0"
}

Related

Load multiple Jenkins pipeline scripts from Git via Job DSL seed script

My use case: I want to set up a Jenkins configuration via the Jenkins Helm chart, using the JCasC plugin. I would also like to define a number of jobs via the Pipeline plugin in a series of Jenkinsfiles, so that the entire setup is configured in code, with a clean, complete installation able to be performed just by running helm install.
However, I'm having trouble loading my Pipeline scripts. In my JCasC, I have defined a Job DSL seed script as follows:
job('seedJob') {
scm {
git {
remote {
url 'ssh://git#foo/bar.git'
credentials 'creds'
}
}
}
steps {
dsl {
external 'jenkins/jobs/*.groovy'
}
}
}
This successfully pulls the scripts from the repo, an example of which is:
pipeline {
// hello.groovy
// Do stuff
}
However, the job fails when parsing the Pipeline script with the following error:
ERROR: (hello.groovy, line 1) No signature of method: hello.pipeline() is applicable for argument types: (hello$_run_closure1) values: [hello$_run_closure1#4c6f43b6]
Possible solutions: pipelineJob(java.lang.String), pipelineJob(java.lang.String, groovy.lang.Closure)
Finished: FAILURE
My suspicion is that Pipeline scripts can't be read this way via Job DSL. If this is the case, is there are way I can achieve the loading of multiple Pipeline scripts from a single seed job?
Seed jobs should look like:
pipelineJob('job_name_here') {
definition {
cpsScm {
scm {
git {
branches('*/master')
branches('*/release')
remote {
credentials('credentials_id_from_jenkins_here')
name('name')
url('git#gitlab_repo_here.git')
}
}
}
}
}
triggers {
gitlab {
ciSkip(true)
triggerOnPush(true)
triggerOnMergeRequest(false)
triggerOnClosedMergeRequest(true)
branchFilterType('RegexBasedFilter')
targetBranchRegex('(.*master.*|.*release.*)')
secretToken('paste_secret_token_for_webhook_here')
}
}
}

SonarQube not showing test Jacoco coverage for JUnit tests in a Gradle multi-project

I would like to show the test coverage of a multiple project Spring boot application build with Gradle 6.0. We currently use JUnit5.
The test coverage shows 0% in SonarQube even though a few first tests exists.
The build.gradle files in the top level project (https://github.com/OpenReqEU/eclipse-plugin-vogella/blob/master/server/build.gradle) has the following input:
plugins {
id "org.sonarqube" version "2.7"
id 'jacoco'
}
repositories {
jcenter()
}
subprojects {
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
jcenter()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
jacocoTestReport {
reports {
xml.enabled true
xml.destination file("${buildDir}/coverage-reports/coverage.xml")
//html.destination file("${buildDir}/coverage-reports")
}
}
ext {
springBootVersion = '2.1.1.RELEASE'
}
sourceCompatibility = 1.8
}
wrapper {
gradleVersion = '6.0'
}
In the Jenkins build we set the following parameters:
sonar.projectKey=eclipse-plugin-vogella
sonar.sources=server/com.vogella.prioritizer.server/src/main,server/com.vogella.prioritizer.server.bugzilla/src/main,server/com.vogella.prioritizer.server.issue.api/src/main
sonar.java.binaries=com.vogella.prioritizer.server/build/classes/java/main,com.vogella.prioritizer.server.bugzilla/build/classes/java/main,com.vogella.prioritizer.server.issue.api/build/classes/java/main
sonar.tests=server/com.vogella.prioritizer.server/src/test,server/com.vogella.prioritizer.server.bugzilla/src/test
sonar.coverage.jacoco.xmlReportsPath=server/com.vogella.prioritizer.server.bugzilla/build/jacoco/test.exec,server/com.vogella.prioritizer.server/build/jacoco/test.exec,server/com.vogella.prioritizer.server.issue.api/build/jacoco/test.exec
The result of the build shows an error:
INFO: parsing [/home/jenkins/workspace/issue-prioritizer/coverage-reports/coverage.xml]
ERROR: Reports path not found or is not a directory: /home/jenkins/workspace/issue-prioritizer/coverage-reports/coverage.xml
I see that each project has a generated ${buildDir}/coverage-reports/coverage.xml file but the root file is empty, which is expected as I did not configure anything related to this.
At some point I added a copy task which copied one of the generated xml files from one project into the root folder but the build job complained that the classes were not matching.
Does anybody know how this issue can be solved? I assume I must add a configuration to add a root coverage.xml file which is the aggregate of the individual ones but I have not found a solution for that.
I also tried to apply the jacoco to the root project but that also failed as the root project is not a Java project.
Need to generate report in xml format. Add the sonar property to the xml path as below.
jacocoTestReport {
reports {
xml.enabled true
}
}
sonarqube {
properties {
property "sonar.java.source", "1.8"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.jacoco.reportPaths", "build/reports/jacoco/test/jacocoTestReport.xml"
}
}
Run the gradle command with the jacocoTestReport
gradlew sonarqube jacocoTestReport
I managed to create the aggregated coverage.xml file by changing the top level build.gradle to:
plugins {
// id "org.sonarqube" version "2.7"
id 'jacoco'
}
repositories {
jcenter()
}
subprojects {
println name;
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
jcenter()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
jacocoTestReport {
reports {
xml.enabled true
}
}
ext {
springBootVersion = '2.1.1.RELEASE'
}
sourceCompatibility = 1.8
}
// run the build with ./gradlew clean build generateMergedReport
task generateMergedReport(type: JacocoReport) {
dependsOn = subprojects.test
additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories.setFrom files(subprojects.sourceSets.main.output)
executionData.setFrom project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')
println executionData;
reports {
xml.enabled true
xml.destination file("../coverage-reports/coverage.xml")
}
}
wrapper {
gradleVersion = '6.0'
}
And changing the Jenkins to build generateMergedReport:
cd server && ./gradlew build generateMergedReport
The SonarQube properties where changed to:
sonar.projectKey=eclipse-plugin-vogella
sonar.sources=server/com.vogella.prioritizer.server/src/main,server/com.vogella.prioritizer.server.bugzilla/src/main,server/com.vogella.prioritizer.server.issue.api/src/main
sonar.java.binaries=com.vogella.prioritizer.server/build/classes/java/main,com.vogella.prioritizer.server.bugzilla/build/classes/java/main,com.vogella.prioritizer.server.issue.api/build/classes/java/main
Unfortunately SonarQube still doesnt find the coverage.xml file.
INFO: parsing [/home/jenkins/workspace/issue-prioritizer/coverage-reports/coverage.xml]
ERROR: Reports path not found or is not a directory: /home/jenkins/workspace/issue-prioritizer/coverage-reports/coverage.xml
Does someone have an idea of what is missing?

Running shell scripts in a Jenkins DSL mavenJob

I'm writing a Jenkins (version 2.6) DSL that will allow me to check out and build a Maven project, run a shell script and deploy it to Artifactory.
mavenJob("test-build") {
multiscm {
...
}
steps {
shell ("bash build-scripts/script.sh")
}
goals("clean install")
configure{ project ->
project/publishers << 'org.jfrog.hudson.ArtifactoryRedeployPublisher' {
details {
artifactoryUrl('<url>')
artifactoryName('<name>')
repositoryKey('libs-release-local')
snapshotsRepositoryKey('libs-snapshot-local')
}
deployBuildInfo(true)
deployArtifacts(true)
evenIfUnstable(false)
}
publishers {
archiveJunit('target/*/.xml')
publishBuilder {
discardOldBuilds(7,10)
}
}
}
The job only works if I remove the steps{} block as steps aren't permitted in a mavenJob. I've tried using a freeStyleJob, but ArtifactoryRedeployPublisher doesn't work.
What do I have to do to run my shell script?
If you want shell script to be run ahead of maven goal, you can use this
preBuildSteps {
// Runs a shell script.
shell(String command)
}
Or if you want the shell script run after the maven goal, you can use this one
mavenJob('example-1') {
postBuildSteps {
shell("echo 'run after Maven'")
}
}
For detail, you can check the job dsl api viewer
https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.jobs.MavenJob.postBuildSteps
It is very easy and handy tool.
Br,
Tim

Grails gradle: How to set System Property

May I know why I'm unable to set the System Property with the systemProperty method when using the grails-gradle-plugin?
My build.gradle as follows:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.0.0"
}
}
version "0.1"
group "example"
apply plugin: "grails"
repositories {
grails.central() //creates a maven repo for the Grails Central repository (Core libraries and plugins)
}
grails {
grailsVersion = '2.3.5'
groovyVersion = '2.1.9'
springLoadedVersion '1.1.3'
}
dependencies {
bootstrap "org.grails.plugins:tomcat:7.0.50" // No container is deployed by default, so add this
compile 'org.grails.plugins:resources:1.2' // Just an example of adding a Grails plugin
}
test {
println "I'm in the test"
//Could not find method systemProperty() for arguments [geb.env, sauce] on root project
systemProperty 'geb.env', 'sauce'//Fails
}
In the test task, I get the following error when i run $gradle grails-test:
Could not find method systemProperty() for arguments [geb.env, sauce] on root project..."
Is this a problem with the grails-gradle plugin since other plugins like "java" allows me to use setProperty? Thanks.
The error message is correct: there's no systemProperty() method.
As Joshua Moore comments, this should work:
test {
println "I'm in the test"
System.setProperty 'geb.env', 'sauce'
}

IntelliJ IDEA: Gradle indexing files - infinite loop

I'm developing a web application, using Grails 2.2.3 with Ember.js (rc3). I'm using IntelliJ IDEA 12.1 Utlimate as IDE and also the IntelliJ TeamCity CI Server - everything's on Windows 7 Professional SP1. Now I wanted to use Gradle 1.7 to better organize my build tasks (combining Grails, Grunt, testing and so on...) and I expected paradise but all I got was hell...
As soon as I started to use the gradle.build file and started JetGradle in IntelliJ IDEA it started to scan and index files over and over (actually it is still running now - 14 hours and counting), the IDE is blocked and I can't do anything... it's really frustrating.
If it's of any interest, here's my gradle.build:
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.Exec
import org.grails.gradle.plugin.GrailsTask
buildscript {
repositories {
maven { url "http://my.company.archiva:8080/repository/internal" }
maven { url "http://repo.grails.org/grails/repo" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT",
"org.grails:grails-bootstrap:2.2.3"
}
}
apply plugin: "grails"
apply plugin: "base"
repositories {
maven { url "http://my.company.archiva:8080/repository/internal" }
maven { url "http://repo.grails.org/grails/repo" }
}
grails {
grailsVersion "2.2.3"
}
configurations {
all {
exclude module: "commons-logging"
exclude module: "xml-apis"
exclude module: "grails-plugin-log4j"
exclude module: "slf4j-log4j12"
}
test {
exclude module: "groovy-all"
}
compile {
exclude module: "hibernate"
}
compileOnly
}
dependencies {
compile("com.my.company:grails-custom-plugin1:0.1.7#zip")
compile("com.my.company:grails-cusotm-plugin:0.2#zip")
compile("com.my.company:backendapi:1.1")
compile("org.mozilla:rhino:1.7R4")
compile("io.netty:netty:3.3.1.Final")
compile("com.google.protobuf:protobuf-java:2.4.1")
compile("org.grails.plugins:cache:1.0.1")
compileOnly "org.grails:grails-plugin-tomcat:$grails.grailsVersion" // No tomcat-*.jar in the war
bootstrap "org.codehaus.groovy:groovy-all:2.0.5"
}
/*
GRADLE Wrapper
*/
task wrapper(type: Wrapper) {
gradleVersion = '1.7'
}
/*
GRUNT Section
*/
task npm(type: Exec) {
group = "Build"
description = "Installs all Node.js dependencies defined in package.json"
workingDir "web-app"
commandLine = ["npm.cmd", "install"]
inputs.file "package.json"
outputs.dir "node_modules"
}
task production(type: GruntTask) {
gruntArgs = "prod"
}
class GruntTask extends Exec {
private String gruntExecutable = Os.isFamily(Os.FAMILY_WINDOWS) ? "grunt.cmd" : "grunt"
private String switches = "--no-color"
private String workDir = "web-app"
String gruntArgs = ""
public GruntTask() {
super()
this.setExecutable(gruntExecutable)
this.workingDir(workDir)
}
public void setGruntArgs(String gruntArgs) {
this.args = "$switches $gruntArgs".trim().split(" ") as List
}
}
/*
WAR creation
*/
task war(type: GrailsTask) {
command "war"
env "prod"
}
Is anybody out there who is able to help me? I searched the internet up and down but it seems that either nobody is using the combination of Grails, Ember.js, Gradle, IntelliJ IDEA or everything is dead simple and I'm just to stupid to use the tools...
I don't recommend to use the Gradle integration in IDEA 12 as it's too limited. (IDEA 13 will be better.) Instead you can use Gradle's "idea" plugin to generate IDEA files. Not sure how well all of this works together with Grails. Grails' own build tool is deeply integrated with the rest of Grails, and from what I've heard, using anything else means to make compromises. (I don't have first-hand experience though.) There have been plans for Grails to switch over its built-in build tool to Gradle one day.
PS: I'd search the IDEA issue tracker and file an issue if there is none.

Resources