debugMinor
Jenkins try-catch the actual error instead of hudson.AbortException
Viewed 0 times
theerrorhudsonactualjenkinscatchabortexceptioninsteadtry
Problem
how do I get the actual exception of a failed pipeline step/plugin?
I have the following pipeline code
which always results in
But running without try/catch it would result in:
```
hudson.plugins.git.GitException: Failed to fetch from https://git.repo.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1003)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1245)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1309)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:97)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:84)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress --prune --depth=1 -- https://git.repo.git +refs/heads/:refs/remotes/origin/" returned status code 128:
stdout:
stderr: fatal: Unable to create '/var/jenkins_home/workspace/some_space/.git/shallow.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in th
I have the following pipeline code
try {
checkout(
scm: [ ... ]
)
} catch (error) {
echo error.getClass()
echo error.getMessage()
}which always results in
class hudson.AbortException
Error fetching remote repo 'origin'But running without try/catch it would result in:
```
hudson.plugins.git.GitException: Failed to fetch from https://git.repo.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1003)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1245)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1309)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:97)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:84)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress --prune --depth=1 -- https://git.repo.git +refs/heads/:refs/remotes/origin/" returned status code 128:
stdout:
stderr: fatal: Unable to create '/var/jenkins_home/workspace/some_space/.git/shallow.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in th
Solution
What you are referring to here is exception chaining. I don't think you can catch a specific exception in the chain. You can walk the chain to see all the exceptions. To get the last exception, the
GitException, you can use this code.Context
StackExchange DevOps Q#17774, answer score: 1
Revisions (0)
No revisions yet.