How to identify exactly where exception occurred in Jenkins pipeline?

2020-07-30 Thread Gajanan Mahajan
In Jenkins pipeline build, sometimes I've seen null pointer or other 
exceptions like -

java.lang.NullPointerException: Cannot invoke method trim() on null 
object

Generally if we run Java program through IDE or command line, if an 
exception occurs we see at which line number the exception has occurred.

But with Jenkins build output console, it does not show the line number 
where the exception has occurred.

In this case, based on method name ie `trim()` from log, I check wherever 
`trim()` method is used. But as I've used it at multiple places in same 
method, it becomes difficult to identify exactly where error has occurred.

Another way is to add echo statements and re-run build and see where it 
gives this exception but this is time consuming.

Is there any better way/plugin using which I can identify at which line of 
pipeline code exception has occurred?

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/de0645e5-6edb-4d52-ae0d-03c2667fb3b6o%40googlegroups.com.


Re: Jenkins hang on startup after "Listed all plugins"

2020-07-30 Thread Randall Becker
In case anyone is curious, I identified two sources of this issue.

1) JGit is throwing exceptions because nanosecond resolution is set to 
UNDEFINED and any time you do math (add a value) with that value in Java 
long, you get an Arithmetic Overflow. This seems to have left some threads 
in an indeterminate state.
2) More importantly, we had an out of date SSL certificate. There were no 
exceptions thrown during startup relating to this, but we could not get to 
the update site or download metadata on startup. I think this was the root 
of many problems but it would have been nice to get an exception (and one 
with the URL involved, which Jenkins plugins are notorious for not 
reporting).

Cheers,
Randall

On Tuesday, 28 July 2020 10:05:16 UTC-4, Randall Becker wrote:
>
> This has been going on since 2.233. We are getting pretty consistent 
> failures of Jenkins right after the "Listed all plugins" message is logged. 
> This just on the controller (there are no agents), running JRE 1.8.0_45. I 
> have wiped the configuration three times already. As soon as I add pipeline 
> jobs and actually do a build, I cannot stop and restart Jenkins. There are 
> no weird exceptions showing in the log. This has been reported as a defect 
> to Core, with a thread dump, but I have not had any feedback at all. It's 
> getting seriously frustrating. Has anyone else seen this or have advice on 
> tracking down what's going on?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/e10ae546-1381-47b1-a6b2-36e1bf4a667co%40googlegroups.com.


Re: cannot get build causes

2020-07-30 Thread 'Gavin Davies' via Jenkins Users
Try nesting that in a script block

pipeline {
agent any
stages {
stage('example') {
steps {
*  script {*
def causes = currentBuild.getBuildCauses()
echo "Causes are ${causes}"
*  }*
}
}
}
}

On Wed, Jul 29, 2020 at 10:04 PM Tom Brownridge 
wrote:

> Hello,
>
> I am new and am fundamentally misunderstanding pipeline syntax and cannot
> relate the examples in the documentation. What am I missing?
>
> Looking at the example here:
> https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/get-build-cause/getBuildCause.groovy,
> I see a code snippet like this:
>
> def causes = currentBuild.getBuildCauses()
>
> But when I try to write a pipeline script to use it:
>
> pipeline {
> agent any
> stages {
> stage('example') {
> steps {
> def causes = currentBuild.getBuildCauses()
> echo "Causes are ${causes}"
> }
> }
> }
> }
>
> I get the following error:
>
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> WorkflowScript: 6: Expected a step @ line 6, column 17.
>def causes = currentBuild.getBuildCauses()
>^
>
> 1 error
>
>   at 
> org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
>   at 
> org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
>   at 
> org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
>   at 
> org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
>   at 
> org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
>   at 
> groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
>   at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
>   at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
>   at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
>   at 
> org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
>   at 
> org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
>   at 
> org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
>   at 
> org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
>   at 
> org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
>   at hudson.model.ResourceController.execute(ResourceController.java:97)
>   at hudson.model.Executor.run(Executor.java:428)
> Finished: FAILURE
>
> Thanks in advance.
>
> Sincerely,
> Tom
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/da7f2288-490d-40f5-ad6f-693ea3869bdbo%40googlegroups.com
> 
> .
>


-- 
[image: Backbase] *Gavin Davies*
Senior System Engineer · R BA Cardiff Tribe · Cardiff
*O* +31 (0) 20 465 
LinkedIn  · Twitter
 · Careers 

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAONG3Zw4GDUUAzV2JL7GSk%2BWNYwuPXc%2B3eAHMg3D23K23YvhpA%40mail.gmail.com.


Re: cannot get build causes

2020-07-30 Thread Gianluca
Hi,
that is a confusing error in my point of view that you will learn to 
interpret :-) 

The pipeline you wrote is a declarative one and the usage of "def ... " is 
something you can do only in scripted pipelines ... hence, what the error 
really means is: "You forgot to open a script block".

The fix is just to wrap inside a "script" block that allow to execute 
scripted portion inside a declarative pipeline:

pipeline {
agent any
stages {
stage('example') {
steps {
script {
  def causes = currentBuild.getBuildCauses()
  echo "Causes are ${causes}"
}
}
}
}
}

On Wednesday, 29 July 2020 22:04:44 UTC+1, Tom Brownridge wrote:
>
> Hello,
>
> I am new and am fundamentally misunderstanding pipeline syntax and cannot 
> relate the examples in the documentation. What am I missing?
>
> Looking at the example here: 
> https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/get-build-cause/getBuildCause.groovy,
>  
> I see a code snippet like this:
>
> def causes = currentBuild.getBuildCauses()
>
> But when I try to write a pipeline script to use it:
>
> pipeline {
> agent any
> stages {
> stage('example') {
> steps {
> def causes = currentBuild.getBuildCauses()
> echo "Causes are ${causes}"
> }
> }
> }
> }
>
> I get the following error:
>
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> WorkflowScript: 6: Expected a step @ line 6, column 17.
>def causes = currentBuild.getBuildCauses()
>^
>
> 1 error
>
>   at 
> org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
>   at 
> org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
>   at 
> org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
>   at 
> org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
>   at 
> org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
>   at 
> groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
>   at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
>   at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
>   at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
>   at 
> org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
>   at 
> org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
>   at 
> org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
>   at 
> org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
>   at 
> org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
>   at hudson.model.ResourceController.execute(ResourceController.java:97)
>   at hudson.model.Executor.run(Executor.java:428)
> Finished: FAILURE
>
> Thanks in advance.
>
> Sincerely,
> Tom
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/21658d43-59e3-4619-96cc-f4d54ec86299o%40googlegroups.com.