gradle.properties not taking values from command line - jenkins

I have gradle.properties file for which I am passing value from command line as below command but not taking the value.
gradle test -DsystemProp.RunnerApplication=QAEnv -Dgroups=CSP-Smoke
My build.gradle file code as follows-
import java.util.concurrent.TimeUnit
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
classpath group: 'org.testng', name: 'testng', version: '6.8.+'
}
}
plugins {
id 'java'
}
apply plugin: 'java'
group 'org.csp.xxxx'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
test {
systemProperty "RunnerApplication",System.getProperty("RunnerApplication")
reports {
junitXml.enabled = true
html.enabled = true
reports.junitXml.destination = file("test-output/reports/")
}
def Coregroups = System.getProperty('groups','Core-Smoke \n CSP-Smoke')
useTestNG()
{
includeGroups Coregroups
useDefaultListeners = true
options.suites("src/test/java/TestAPISuite.xml")
//options.listeners << 'com.ddddd.smsApi.qa.framework.listener.CustomListener'
//options.listeners << 'com.dddd.smsApi.qa.framework.listener.EmailListener'
options.listeners << 'org.uncommons.reportng.HTMLReporter'
options.listeners << 'org.uncommons.reportng.JUnitXMLReporter'
systemProperty 'org.uncommons.reportng.title', 'csp_api_automation_results'
}
testLogging.events "passed", "skipped", "failed"
testLogging.exceptionFormat = "full"
//Interceptors
beforeTest { desc ->
println "\n*** Starting execution of test ${desc.className}.${desc.name} ***"
}
afterTest { descriptor, result ->
println "<<< Test ${descriptor.name} resulted in ${result.resultType} and took "+getElaspedTime(result.endTime - result.startTime)+" >>>\n"
}
//Modify the test logging
testLogging {
showStandardStreams = true
exceptionFormat "full"
}
}
sourceSets {
main {
runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
}
test {
runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
}
}
dependencies {
compile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.2'
testCompile group: 'org.testng', name: 'testng', version: '6.8.+'
//An assertion library that is better than JUnit defaults
testCompile 'org.easytesting:fest-assert-core:2.0M10'
//Better reporting for testng. It outputs a nice html report
testCompile 'org.uncommons:reportng:1.1.4'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15'
compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'com.googlecode.htmlcompressor', name: 'htmlcompressor', version: '1.5.2'
compile group: 'commons-dbutils', name: 'commons-dbutils', version: '1.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
compile group: "com.github.fge", name: "json-schema-validator", version: "2.2.6"
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.json', name: 'json', version: '20160810'
compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
compile group: 'com.google.code.guice-repository', name: 'guice-repository', version: '2.1.0'
compile group: 'org.easytesting', name: 'fest-assert-core', version: '2.0M10'
compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.5'
compile group: 'org.apache.commons', name: 'commons-exec', version: '1.3'
compile group: 'com.opencsv', name: 'opencsv', version: '4.1'
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
compileClasspath group: 'org.testng', name: 'testng', version: '6.8.+'
// https://mvnrepository.com/artifact/com.cedarsoftware/json-io
compile group: 'com.cedarsoftware', name: 'json-io', version: '2.6.0'
// https://mvnrepository.com/artifact/org.apache.poi/poi
compile group: 'org.apache.poi', name: 'poi', version: '3.17'
// https://mvnrepository.com/artifact/com.aventstack/extentreports
compile group: 'com.aventstack', name: 'extentreports', version: '4.0.9'
}
def getElaspedTime(def time) {
if(time / 1000 < 1)
{
return String.format("0 min, %.3f sec", time/1000)
}
else
{
return String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))
)
}
}
systemProp.RunnerApplication=dev is the key and value saved in my gradle.properties.
Here I want to run as RunnerApplication=QAEnv so automation can run in different environments
But its is always running on dev even Passing QAEnv in command line.
I would really appreciate your help.

You are passing in two system properties. One is prefixed with systemProp. and the other isn't. This should indicate to you that one of them is wrong. And it's the former :)
There is a use for the systemProp. prefix, but only when declaring system properties through the gradle.properties file. Here, you are declaring them from the command line.
So instead of:
gradle test -DsystemProp.RunnerApplication=QAEnv -Dgroups=CSP-Smoke
Run:
gradle test -DRunnerApplication=QAEnv -Dgroups=CSP-Smoke

Related

IntelliJ:Rest Assured getting missing input or config

Can anyone help me
Project has been cloned from Bitbucket and locally when i am running the project in the intelliJ the error is displayed
Unable to run the scripts-rest assured in the IntelliJ getting missing input or config. Getting build failure if I change the swagger code-gen dependency also same error is displayed
this is my gradle.build
Buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("io.swagger:swagger-codegen:2.3.1")
}
}
plugins {
id 'java'
id 'io.qameta.allure' version '2.8.1'
}
repositories {
mavenCentral()
}
group 'org.example'
version '1.0-SNAPSHOT'
apply plugin: 'base'
import io.swagger.codegen.DefaultGenerator
import io.swagger.codegen.config.CodegenConfigurator
final def swaggerInput = "swagger.json"
final def swaggerOutputDir = file('build/swagger')
task generateApi {
inputs.file(swaggerInput)
outputs.dir(swaggerOutputDir)
doLast {
final def config = new CodegenConfigurator()
config.setInputSpec(swaggerInput)
config.setOutputDir(swaggerOutputDir.path)
config.setLang('java')
config.setAdditionalProperties([
'dateLibrary' : 'java8'])
config.setImportMappings([
'java.time.OffsetDateTime': 'java.time.Instant',])
config.setTypeMappings([
OffsetDateTime: 'Instant',])
new DefaultGenerator().opts(config.toClientOptInput()).generate()
}
}
clean.doFirst {
delete(swaggerOutputDir)
}
configurations {
swagger
}
sourceSets {
swagger {
compileClasspath = configurations.swaggerCompile
java {
srcDir file("${project.buildDir.path}/swagger/src/main/java")
}
}
main {
compileClasspath += swagger.output
runtimeClasspath += swagger.output
}
test {
compileClasspath += swagger.output
runtimeClasspath += swagger.output
}
}
compileSwaggerJava.dependsOn generateApi
classes.dependsOn swaggerClasses
compileJava.dependsOn compileSwaggerJava
allure {
version = '2.7.0'
downloadLinkFormat = 'https://github.com/allure-framework/allure2/releases/download/2.7.0/allure-2.7.0.zip'
}
dependencies {
// https://mvnrepository.com/artifact/io.rest-assured/rest-assured
compile group: 'io.rest-assured', name: 'rest-assured', version: '4.3.0'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.11.0'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.0'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.11.0'
// https://mvnrepository.com/artifact/org.json/json
compile group: 'org.json', name: 'json', version: '20190722'
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.6'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.6'
compile group: 'com.google.code.gson', name: 'gson', version: '2.1'
compile group: 'io.gsonfire', name: 'gson-fire', version: '1.7.1'
// https://mvnrepository.com/artifact/org.testng/testng
compile group: 'org.testng', name: 'testng', version: '7.0.0'
// https://mvnrepository.com/artifact/org.assertj/assertj-core
compile group: 'org.assertj', name: 'assertj-core', version: '3.16.0'
// https://mvnrepository.com/artifact/io.qameta.allure/allure-rest-assured
compile group: 'io.qameta.allure', name: 'allure-rest-assured', version: '2.13.5'
// https://mvnrepository.com/artifact/io.qameta.allure/allure-testng
compile group: 'io.qameta.allure', name: 'allure-testng', version: '2.13.5'
// https://mvnrepository.com/artifact/org.aeonbits.owner/owner
compile group: 'org.aeonbits.owner', name: 'owner', version: '1.0.10'
// AWS SDK dependencies
compile 'com.amazonaws:aws-java-sdk:1.12.335'
compile 'com.amazonaws:aws-java-sdk-core:1.12.335'
compile 'com.amazonaws:aws-java-sdk-cognitoidp:1.12.335'
compile 'com.amazonaws:aws-java-sdk-ssm:1.12.335'
compile 'software.amazon.awssdk:ssm:2.18.10'
compile 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
compile 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
swaggerCompile 'io.swagger:swagger-annotations:1.5.16'
swaggerCompile 'com.squareup.okhttp:okhttp:2.7.5'
swaggerCompile 'com.squareup.okhttp:logging-interceptor:2.7.5'
swaggerCompile 'com.google.code.gson:gson:2.8.1'
swaggerCompile 'io.gsonfire:gson-fire:1.7.1'
compile sourceSets.swagger.output
testCompile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.4'
testCompile 'org.elasticsearch:elasticsearch:6.2.4'
compile 'com.squareup.okio:okio:1.8.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
}
test() {
useTestNG() {
if (project.hasProperty('qa4')) {
environment 'env', 'qa4'
}
if (project.hasProperty('qa5')) {
environment 'env', 'qa5'
}
if (project.hasProperty('qa6')) {
environment 'env', 'qa6'
}
if (project.hasProperty('qa7')) {
environment 'env', 'qa7'
}
if (project.hasProperty('qa8')) {
environment 'env', 'qa8'
}
if (project.hasProperty('qa9')) {
environment 'env', 'qa9'
}
if (project.hasProperty('party_controller')) {
suites 'src/test/resources/suites/party_controller.xml'
}
if (project.hasProperty('account_controller')) {
suites 'src/test/resources/suites/account_controller.xml'
}
if (project.hasProperty('payment_source_controller')) {
suites 'src/test/resources/suites/payment_source_controller.xml'
}
if (project.hasProperty('transaction_controller')) {
suites 'src/test/resources/suites/transaction_controller.xml'
}
if (project.hasProperty('maxmind_controller')) {
suites 'src/test/resources/suites/maxmind_testing.xml'
}
if (project.hasProperty('parallel_execution')) {
suites 'src/test/resources/suites/parallel_execution.xml'
}
if (project.hasProperty('regression')) {
suites 'src/test/resources/suites/party_controller.xml'
suites 'src/test/resources/suites/account_controller.xml'
suites 'src/test/resources/suites/payment_source_controller.xml'
suites 'src/test/resources/suites/transaction_controller.xml'
suites 'src/test/resources/suites/maxmind_testing.xml'
suites 'src/test/resources/suites/parallel_execution.xml'
}
}
afterSuite { final suite, final result ->
result.exception?.printStackTrace()
}
}

Can't load resources in a gradle project

I am using gradle 4.10.2 & IntelliJ IDEA Community Edition 2018.2
Note that this is a jenkins shared library project, hence, deviates from the standard gradle project structure.
The project shown in the image is an existing Gradle project. I am simply trying to load a properties file viz. mailTemplate.properties in a Groovy class EmailTemplate but the problem is that irrespective of where I keep it(like shown in the image), it's not loaded. I created a separate test gradle project and placed it in the default (src/main/resources) dir. and it works like a breeze.
I tried creating 'resources' at two places but in vain.
The build.gradle is:
buildscript {
repositories {
ivy {
url "$repositoryURL/$resolveRepository"
}
maven {
url "$repositoryURL/$resolveRepository"
}
}
dependencies {
classpath "tools.gradle.plugin:ReleasePlugin:1.10.0"
classpath "tools.gradle.plugin:qualityreport:v1.14.4"
}
}
group 'tools'
apply plugin: 'groovy'
apply plugin: 'tools.gradle.plugin.releaseplugin'
apply plugin: 'tools.gradle.plugin.qualityreport'
sourceSets {
main {
groovy {
srcDirs = ['src']
}
}
test {
groovy {
srcDirs = ['test/groovy']
}
}
}
repositories {
addAll(buildscript.repositories)
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.15'
compile 'org.codehaus.groovy:groovy-json:2.4.9'
compile 'com.cloudbees:groovy-cps:1.1'
compile 'org.slf4j:slf4j-api:1.7.21'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'net.bytebuddy:byte-buddy:1.6.4'
testCompile ('org.spockframework:spock-core:1.1-groovy-2.4') {
exclude group: 'org.codehaus.groovy'
}
testCompile gradleTestKit()
testCompile group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: '1.1'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
testCompile group: 'tools.gradle.plugin', name: 'jenkins-shared-stages', version: 'v2.48.0'
// jenkins dependencies
testCompile 'org.jenkins-ci.plugins:script-security:1.34#jar'
}
task copySharedLibs(type: Copy, group: "PipelineTest") {
from '.'
into 'build/libs/jenkins-shared-pipelines#master'
include 'src/**'
include 'vars/**'
}
test.dependsOn(copySharedLibs)
Gradle groovy plugin expects resources to be at src/main/resources by default. In case the resources are located some other folder then it should be configured in the sourceSets. You can try the below assuming your resource file are also withing your src folder.
sourceSets {
main {
groovy {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
}
}
test {
groovy {
srcDirs = ['test/groovy']
}
resources {
srcDirs = ['test/groovy']
}
}
}

Use variable in nexusArtifactUploader/Jenkinsfile

I have this Jenkins DSL script which gets the version from pom.xml file and uses that version in nexusArtifactUploader. This is currently not working and I am getting "groovy.lang.MissingPropertyException: No such property: version for class: groovy.lang.Binding" error. I am new to Groovy/Jenkins DSL and don't know how to make it work.
stage('Nexus') {
steps {
script {
def pom = readMavenPom file: 'pom.xml'
echo pom.version
nexusArtifactUploader(
nexusVersion: 'nexus3',
protocol: 'http',
nexusUrl: 'nexus.example.com:8080/nexus',
groupId: 'com.example',
**version: "${pom.version}",**
repository: 'example',
credentialsId: 'ciuser',
artifacts: [
[artifactId: 'com.example',
file: 'com.example-' + version + '.jar',
type: 'jar']
]
)
}
}
}
I think your error is actually on this line:
file: 'com.example-' + version + '.jar',
Try replacing version with pom.version.

Building uberjar with gradle fails in jenkins

Hi I'm using gradle to create a fat jar.
It works properly on my local machine but fails when running from Jenkins.
My local gradle version is: GradleVersion.current().getVersion()=2.2.1
The one in Jenkins: GradleVersion.current().getVersion()=2.4
build.gradle looks like
Is there anything about gradle version?
I just run tasks: clean uberjar
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenLocal()
mavenCentral()
}
def classifier = 'producao'
println "GradleVersion.current().getVersion()="+ GradleVersion.current().getVersion()
println "Project env = '${project.hasProperty('env')}'"
// para passar parametros -Penv=homologacao
if (project.hasProperty('env') && project.getProperty('env') == 'homologacao') {
classifier = 'homologacao'
}
println "Classifier = ${classifier}"
println "Using 'com.mundi:OneStop:1.0:${classifier}'"
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.10'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile 'net.sf.opencsv:opencsv:2.3'
compile "com.mundi:OneStop:1.0:${classifier}"
compile 'org.apache.commons:commons-lang3:3.4'
testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile "org.spockframework:spock-core:1.0-groovy-2.3"
}
task listJars << {
configurations.compile.each { File file -> println file.name }
}
test { systemProperties 'property': 'value' }
uploadArchives {
repositories { flatDir { dirs 'repos'
} }
}
task copyToLib(type: Copy) {
into "build/classes/main"
sourceSets {
main { resources { srcDir 'src/main/resources' } }
}
from sourceSets.main.resources
}
task uberjar(type: Jar, group:'Extra Jars', description: 'Assembles a single uber jar archive containing the main classes along with all its dependencies.',
dependsOn:[':copyToLib',
':compileJava',
':compileGroovy',
':processResources'
]) {
classifier = 'uber'
destinationDir new File("$buildDir")
from files(sourceSets.main.output.classesDir)
from(configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }) {
//exclude all META-INF that may appear in any dependant jar
exclude "META-INF/**"
}
version = '1.0'
baseName = "OneStopMonitor"
manifest {
attributes 'Main-Class': "com.onestop.monitor.AirMonitor",
'Implementation-Title': 'OneStop Monitor',
'Implementation-Version': version
}
}
group = 'com.onestop'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file:///Users/eduardorodrigues/.m2/repository")
}
}
}

Grails 3 asset-pipeline / coffee-asset pipeline

I am using asset-pipeline to manage my front end resources for my Grails 3.0 application. However it seems that source-maps for CoffeeScript files are not created. Is there any way to enable this?
My build.gradle is as follows:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.6.2'
classpath 'com.bertramlabs.plugins:coffee-asset-pipeline:2.6.2'
classpath "org.grails.plugins:hibernate:4.3.10.5"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
}
version "0.1"
group "grails2"
apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: "asset-pipeline"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
enableSourceMaps = true
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:scaffolding"
runtime "org.grails.plugins:asset-pipeline"
runtime 'com.bertramlabs.plugins:coffee-asset-pipeline:2.6.2'
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
// Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'
console "org.grails:grails-console"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
This is my application.coffee
#= require test
#= require_tree .
#= require_self
console.log "This is my manifest"
$ ->
$("#spinner")
.ajaxStart -> $(this).fadeIn()
.ajaxStop -> $(this).fadeOut()
And have included the following tag in my main.gsp:
<asset:javascript src="application.coffee"/>
However, the source I get in the Chrome Browser Developer tools is the following:
// Generated by CoffeeScript 1.9.2
(function() {
console.log("This is my manifest");
$(function() {
return $("#spinner").ajaxStart(function() {
return $(this).fadeIn();
}).ajaxStop(function() {
return $(this).fadeOut();
});
});
}).call(this);
source, what you see, is actually coffee script "translated" into pure JS. From main page of Coffescript
"CoffeeScript is a little language that compiles into JavaScript."
(http://coffeescript.org)

Resources