Jenkins Pipeline - how to javadoc a global pipeline library? - jenkins

Is there a way to run javadoc or the groovy equivalent against a global pipeline library? I out of habit wrote comments for every method that follow the javadoc format - would love if I could run javadoc against the library and have doc generated.

As described in the documentation, global variables (inside vars/) are documented in a <name>.txt file next to the <name>.groovy file.
Groovy classes within src/ are.. well.. just Groovy code and thus GroovyDoc should be used.

Related

Jenkins/Groovy move variables out to a config file

I've been asked to move some variable from a Groovy script out into a configuration file. I'm fine using something like :-
readFile('../xx-software.cfg').split('\n').each { fileName ->
sh "wget ${theURL}${fileName}"
}
However, even though I have added xx-software.cfg into the same directory as my Groovy script it does become available for use within that groovy script.
I hope this makes sense!?
How can I move my variables out into a config file to make it easier for the application support team to make future edits without changing the code?
There are a few approaches you could use.
Firstly, file format for the configuration and how to read the data into variables. You could use Java Properties format, YAML or JSON and these are all handled by the Pipeline Utility Steps plugin with steps here. You can read the file with these steps:
readProperties
readYaml
readJSON
Next problem, how to get the file available to your pipeline so it can be read from the workspace using these steps. Possibilities are:
In source control with your pipeline code. It can be fetched with the pipeline.
In a separate source control for configuration, your pipeline will need a step to fetch it.
Use the Jenkins Config File Provider plugin. It has a step to provide a config file managed in Jenkins.
Provide it as a Custom Tool zipped archive from a binary server like Artifactory. You can use custom tool definition pipeline steps to make this available to the pipeline.
The Config File Provider option might provide any easy way to have a file that can be updated, but there won't be any version control of it.

Jenkins javadoc plugin doesn't generate documentation

I have installed Jenkins, create a project and configure it.
I run into a problem, Jenkins do everithing great except documentation generating.
Could anyone point me where I have done mistake, and how fix it?
Thank you.
------------------------ New information ----------
Console output:
I have renamed doc to javadoc directory, but it isn't help.
Here is screenshot of javadoc directory contents in console, it is clear that Jenkins plugin didn't generate documentation, but why?
It sounds like you are expecting the Jenkins plugin to produce the documentation. The Jenkins plugin merely copies files from the job's workspace folder to the build's archive area and provides a link to it. If your build steps don't produce Javadoc, then Jenkins won't be able to archive and provide a link to it.
Does your pom file include the maven-javadoc-plugin?
Are your build steps invoking a goal that includes Javadoc generation?
For example, "mvn jar" would compile Java and build the jar but not build the javadocs. Clearly you have executed a goal that executes the tests and provides a code coverage report, but that does not trigger the Javadoc goals either. You would need to make sure your build steps include a javadoc goal - i.e., mvn javadoc:javadoc. The standard goals can be found here: https://maven.apache.org/plugins/maven-javadoc-plugin/plugin-info.html .

Add dependency to jenkins job dsl

I'm trying to add a dependency to my seed job, but no matter what I try, I always get the exception in Jenkins that it can't find the classes that I import in my groovy job. I've tried adding the dependency as compile, testCompile, lib, everything in my build.gradle file, but it doesn't seem to do anything... I'm trying to import org.yaml.snakeyaml.Yaml from the org.yaml:snakeyaml:1.17 dependency.
Any idea on how I can somehow get jenkins to get a hold of that dependency when trying to execute that seed job?
Thanks!
Alternatively you might use Grape to download any dependency directly from your Jenkinsfile. If you add
#Grab(group='org.yaml', module='snakeyaml', version='1.20')
on top of your Jenkinsfile, Jenkins pipeline will download this dependency and it will get available in your pipeline script.
Never mind, I've found the solution. I copied the dependency to a specific folder during the gradle build and added that to the additional classpath of the job dsl. It works now!

Can I use step() to create any build-step from any plugin?

I am currently trying to transform my former "GUI"-build-steps into a pipeline groovy script. I formerly had a step from the valgrind plugin to publish the results of a valgrind run.
I found the "step: General Build Step" function in the Pipeline Syntax Snippet Generator and tried to use it to create the valgrind publish results step with the following code:
// file pipeline.groovy
import org.jenkinsci.plugins.valgrind.*;
...
node('Publish Valgrind results')
{
step([$class: 'ValgrindPublisher', ValgrindPublisherConfig: [$class: 'ValgrindPublisherConfig', pattern: 'CppCodeBase/Generated/ValgrindOutput/**']])
}
...
When I run this jenkins complains:
java.lang.UnsupportedOperationException: no known implementation of interface jenkins.tasks.SimpleBuildStep is named ValgrindPublisher
So I am not sure if the problem is that ValgrindPublisher only derives from BuildStepand not from SimpleBuildStepor if my import is faulty.
The more general question would be:
Is it possible to run any build-step from a plugin in a pipeline script and if so, where can I find examples?
No you cannot. You can only use steps from pipelines-compatible plugins and it appears that your ValgrindPublisher plugin is not (yet) pipeline-compatible.
You can check this answer for similar information.

Automation of documenting code base using Doxygen plug in Jenkins CI environment

I use a shell script to create/run doxygen doxyfile to document my code base
which works absolutely fine(Schedule runs and recursive scan code base also
works fine).
Now my requirement is to do the same job using Jenkins CI.
I added doxygen plug which generates documentation output and stores the result in Jenkin workspace.
My question, is there any another ways to run script and generate doxyfile in
Jenkins environment and also
How to create url link to display doxygen HTML output.
Have you seen the Jenkins DocLink plugin? This plugin makes it easy to put a link on your project page to documentation generated in a build.

Resources