blackducksoftware / hub-detect

This is now deprecated. Please see synopsys-detect.
Apache License 2.0
38 stars 39 forks source link

How to use the exit code in Jenkins? #368

Closed LinkBenjamin closed 5 years ago

LinkBenjamin commented 5 years ago

Hello,

I'm new to BlackDuck and I've been looking over the docs on the Confluence, but I haven't figured out how to make this work. I have a Jenkinsfile where I'm currently calling hub_detect (latest version) as follows:

hub_detect pluginOptions

This works (in order to generically succeed/fail a build), but I'd like to catch the exit code and react differently depending on which code returns, something like this:

switch(hub_detect pluginOptions) { ... }

If I do exactly what I show above, I only ever get 'null' in the switch condition. I tried wrapping the hub_detect call in sh() and adding the return status boolean but that won't work either since it's not a shell call. How can I interrogate my hub_detect call to get the exit code?

johnmccabe commented 5 years ago

It looks like the plugin will always return a success, and doesn't return a step result. Instead it fails the entire build.

https://github.com/jenkinsci/blackduck-detect-plugin/blob/67abac6fa80a95b7f00fdfab634e2291234aff2e/src/main/java/com/blackducksoftware/integration/detect/jenkins/common/DetectCommonStep.java#L99-L101

(the plugin repo has issues disabled)

stavvy-akamen commented 5 years ago

@rottebds I believe this is a Detect Jenkins inquiry, can you help out @LinkBenjamin

rottebds commented 5 years ago

@LinkBenjamin @johnmccabe unfortunately the Detect Jenkins plugin is, at its core, a Jenkins Recorder and will set the status of the build when run. It simply is Jenkins native rather than being Pipeline native, and cannot send information (such as exit codes) to the pipeline plugin.

Detect does, however, offer some means of manipulating the exit code (there is a property, for example, to force detect to quit with exit code 0 when it cannot connect to help prevent CI jobs from failing when connection to BlackDuck is interrupted temporarily)

If that is not sufficient, you can invoke the shell script directly from within Jenkins to have finer grained access to the exit codes returned.

Hope that helps!

LinkBenjamin commented 5 years ago

Thanks for the information!