NULL pointer Exception in Groovy postbuild Script - jenkins

I am using the build flow project for combining the two different project test results.Then i am in need to change the build status of the aggregated test results so i am using groovy postbuild to change my build status.In that script if any one of the test fails gets failed in any of the projects then i am trying to change the build status to unstable.For that i am calculating the fail counts from both results using groovy script.But when i am trying this it throws the NULL pointer Exception.
The script i used in the groovy postbuild is
def testResult = manager.build.testResultAction.result
def fail = testResult.failCount
if(fail==NULL)
{ manager.buildSuccess() }
else
{ manager.buildUnstable() }
It throws the exception as
ava.lang.NullPointerException: Cannot get property 'result' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:156)
at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
at Script1.run(Script1.groovy:1)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:580)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:618)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:166)
at org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.perform(GroovyPostbuildRecorder.java:362)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:723)
at hudson.model.Build$BuildExecution.post2(Build.java:185)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:668)
at hudson.model.Run.execute(Run.java:1763)
at hudson.model.FreeStyleBuild.run``(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Activity

Related

Xray for JIRA Jenkins Plugin, TestNG XML Results Import task failure

this is my 1st question, any help will be greatly appreciated.
I need to import test results from Jenkins to Xray.
To do so I:
set up Xray for JIRA Jenkins Plugin;
configured Xray Server/DC integration with Jenkins;
tested connection and it's successful;
went to my Jenkins project configuration and set up post-build Action 'Xray:Result Import Task';
under parameters of 'Xray:Result Import Task' I was trying to specify Execution Report File (file path with file name).
AND here is my question: what exact input is supposed to be here?
I tried URL to my test execution issue already created in Xray, testng.xml. myTestExecution.xml file - nope. Doesn't work. I'm missing smthng here((
Can't get what is meant by:
file path with file name.
My Results Import task fails with error below.
Starting XRAY: Results Import Task...
##########################################################
#### Xray is importing the execution results ####
##########################################################
0 files found. Please make sure the path provided is valid and is not a directory
ERROR: Build step failed with exception
com.xpandit.plugins.xrayjenkins.exceptions.XrayJenkinsGenericException: 0 files found. Please make sure the path provided is valid and is not a directory
at com.xpandit.plugins.xrayjenkins.Utils.FileUtils.getFiles(FileUtils.java:180)
at com.xpandit.plugins.xrayjenkins.task.XrayImportBuilder.perform(XrayImportBuilder.java:563)
at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:112)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
at hudson.model.Build$BuildExecution.post2(Build.java:186)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
at hudson.model.Run.execute(Run.java:1919)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Build step 'Xray: Results Import Task' marked build as failure
Finished: FAILURE
set up Xray for JIRA Jenkins Plugin;
configured Xray Server/DC integration with Jenkins;
tested connection and it's successful;
went to my Jenkins project configuration and set up 2 post-build Actions:
'Publish TestNG Results'
TestNG XML report pattern: **/target/surefire-reports/testng-results.xml
'Xray:Result Import Task':
Jira Instance: Jira Instance;
Format: TestNG XML;
Execution Report File (file path with file name): **/testng-results.xml (generated by 'Publish TestNG Results' action);
Test Execution Key: JIRA-123 (Jira Test execution issue);

How to run jenkins job from groovy script

is it possible to run jenkins job from groovy script?
I know it is possible to run jenkins job from pipeline like this
build job: 'test'
this also doesn't work
build('test')
error for
build job: 'test'
Caught: groovy.lang.MissingMethodException: No signature of method: hudson8298793087824999032.build() is applicable for argument types: (LinkedHashMap) values: [[job:test]]
Possible solutions: find(), find(groovy.lang.Closure), wait(), run(), run(), dump()
groovy.lang.MissingMethodException: No signature of method: hudson8298793087824999032.build() is applicable for argument types: (LinkedHashMap) values: [[job:test]]
Possible solutions: find(), find(groovy.lang.Closure), wait(), run(), run(), dump()
at hudson8298793087824999032.run(hudson8298793087824999032.groovy:32)
Build step 'Execute Groovy script' marked build as failure
After edit Execute system Groovy script and added
def currentBuild = Thread.currentThread().executable
def job = hudson.model.Hudson.instance.getJob("jobname")
println(job)
def params = new StringParameterValue('version', '1.0.0')
println(params)
def params1 = new StringParameterValue('target', "dev")
println(params1)
def paramsAction = new ParametersAction(params, params1)
println(paramsAction)
def cause = new hudson.model.Cause.UpstreamCause(currentBuild)
println(cause)
def causeAction = new hudson.model.CauseAction(cause)
println(causeAction)
println('test')
Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction)
I got error on this line Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction)
java.lang.NullPointerException
at hudson.model.queue.Tasks.getOwnerTaskOf(Tasks.java:60)
at com.cloudbees.hudson.plugins.folder.ItemDeletion.getItemOf(ItemDeletion.java:197)
at com.cloudbees.hudson.plugins.folder.ItemDeletion.shouldSchedule(ItemDeletion.java:174)
at hudson.model.Queue.schedule2(Queue.java:589)
at hudson.model.Queue.schedule2(Queue.java:712)
at hudson.model.Queue.schedule(Queue.java:705)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:192)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)
at Script1.run(Script1.groovy:47)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:343)
at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95)
at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1818)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Build step 'Execute system Groovy script' marked build as failure
For me, I needed the code to run on the master to have quick access to the Jenkins objects and build a job that has the appropriate permissions to send a mail within the information acquired.
I used the build module Execute system Groovy Script to run the script and appended the following code:
// The job you want to run from groovy
def job = hudson.model.Hudson.instance.getJob("SendEmailJob")
// jobsList is a list of jobs of interest formated as HTML
def body = jobsList
def params = []
params += new StringParameterValue('TO', "<team#example.com>")
params += new StringParameterValue('BODY_AS_HTML', body)
params += new StringParameterValue('SUBJECT', "List of jobs of interest")
def paramsAction = new ParametersAction(params)
def cause = new hudson.model.Cause.UpstreamCause(build)
def causeAction = new hudson.model.CauseAction(cause)
hudson.model.Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction)
This is based on question how-do-i-dynamically-trigger-downstream-builds-in-jenkins

How do I solve "Expected named arguments" for freeStyleJob?

I have several different projects that will be compiled in Jenkins and shall be uploaded to my Nexus3 repository. For that I am using the NexusArtifcalUploader. For some reason I get the following error message although the code is essentially copied from the plugin page of the Jenkins wiki.
java.lang.IllegalArgumentException: Expected named arguments but got [clientmoduleNexusArtifactUploaderJob, org.jenkinsci.plugins.workflow.cps.CpsClosure2#63d801fc]
at org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:511)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeDescribable(DSL.java:291)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
at sun.reflect.GeneratedMethodAccessor463.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
...
My Jenkinsfile calls the uploadToNexus method I created which creates freeStyleJobs:
def uploadToNexus(module) {
def groupId = "com.example"
def moduleVersions = [
"client-module": "1.0.0-SNAPSHOT",
"server-module": "1.0.0-SNAPSHOT",
]
def moduleVersion = moduleVersions.get(module)
def jobName = "${fixModuleName(module)}NexusArtifactUploaderJob"
echo "will run freeStyleJob ${jobName} now..."
freeStyleJob(jobName) {
steps {
nexusArtifactUploader {
nexusVersion('nexus3')
protocol('http')
nexusUrl('nexus:8081')
groupId(groupId)
version(moduleVersion)
repository('maven2_central')
credentialsId('nexus_admin')
artifact {
artifactId('${module}')
type('war')
classifier('debug')
file('${module}.war')
}
}
}
}
}
To my knowledge freeStyleJob expects a string which I pass, don't I? What am I missing and doing wrong?
It seems that I mixed up Job DSL and Pipeline DSL. I wasn't aware there's a difference.
Here's a way to use Job DSL inside Pipeline DSL:
https://github.com/jenkinsci/job-dsl-plugin/wiki/User-Power-Moves#use-job-dsl-in-pipeline-scripts

hudson.AbortException: No files found in path with configured filemask: output.xml

I was running a RobotFramework script using Jenkins and everything was working fine until I accidentally wiped out my current workspace. I don't know how to restore it and now I'm getting the following error:
Robot results publisher started...
-Parsing output xml:
Failed!
hudson.AbortException: No files found in path C:\Users\EEMIZHA\.jenkins\jobs\3PI RF2\workspace with configured filemask: output.xml
at hudson.plugins.robot.RobotParser$RobotParserCallable.invoke(RobotParser.java:77)
at hudson.plugins.robot.RobotParser$RobotParserCallable.invoke(RobotParser.java:54)
at hudson.FilePath.act(FilePath.java:990)
at hudson.FilePath.act(FilePath.java:968)
at hudson.plugins.robot.RobotParser.parse(RobotParser.java:49)
at hudson.plugins.robot.RobotPublisher.parse(RobotPublisher.java:217)
at hudson.plugins.robot.RobotPublisher.perform(RobotPublisher.java:239)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:723)
at hudson.model.Build$BuildExecution.post2(Build.java:185)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:668)
at hudson.model.Run.execute(Run.java:1763)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Build step 'Publish Robot Framework test results' changed build result to FAILURE
Finished: FAILURE
I have the robot plugin installed, I've enabled a "Publish Robot Framework test results" post build action, and I'm executing a very simple Windows Batch Command as follows:
cd C:\Users\EEMIZHA\Documents\3PIManager\Testing\
pybot jenkinsConnectionTest.robot
Any ideas?
Fixed by using a custom workspace in Jenkins set to my \path\to\test (under Advanced Project Options/Advanced...). Run pybot command with -d \path\to\test\output-folder parameter and set output-folder as "Directory of Robot output" in Robot Framework post build action.

Execute "Publish TestNG results" step in Jenkinsfile

I'm trying to convert an existing set of Jenkins jobs to the new pipeline syntax, and I don't understand how to convert the post-build action "Publish TestNG results". The pipeline syntax page doesn't help as this specific action is not listed, so I've tried the following syntax:
step([$class: 'hudson.plugins.testng.Publisher', reportFilenamePattern: 'test-output/testng-results.xml'])
My assumption being that the class name would have to match the content of config.xml in the current configuration:
<hudson.plugins.testng.Publisher plugin="testng-plugin#1.10">
<reportFilenamePattern>test-output/testng-results.xml</reportFilenamePattern>
<escapeTestDescp>true</escapeTestDescp>
<escapeExceptionMsg>true</escapeExceptionMsg>
<showFailedBuilds>false</showFailedBuilds>
<unstableOnSkippedTests>false</unstableOnSkippedTests>
<failureOnFailedTestConfig>false</failureOnFailedTestConfig>
</hudson.plugins.testng.Publisher>
However, an exception is being thrown when executing the statement :
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:193)
at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:104)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:134)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:123)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:123)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15)
at WorkflowScript.testBranch(WorkflowScript:71)
So my questions are :
is it possible to trigger any kind of post-job action using the 'step' statement ?
if yes, is there a rule of thumb to find the class name, and attribute names ?
In case that's relevant for the question, I'm running Jenkins 2.8 with all pipeline plugins up to date, and the full Jenkinsfile can be found on GitHub
Publishing TestNG test results is now available in Pipelines.
Use:
step([$class: 'Publisher'])
or with custom location of the result file:
step([$class: 'Publisher', reportFilenamePattern: '**/custom/testng-results.xml'])
According to this comment on Jenkins Jira adding to Pipeline snippet generator is pending.
(tested on Jenkins 2.9.13 and Pipeline plugin 2.4)
At this time, the TestNG Plugin isn't compatible with Pipelines. See JENKINS-27121

Resources