I have a jenkins global library and I want to document it. I want to use groovydoc.
The library contains classes and global vars
src/<package-name>
vars
Generating documentation for the classes is no problem:
groovydoc -sourcepath src -d doc 'main.pipeline' '*.groovy'
But how can I generate documentation for the vars?
A shared library in Jenkins is a collection of Groovy scripts shared between different Jenkins jobs. To run the scripts, they are pulled into a Jenkinsfile. Each shared library requires users to define a name and a method of retrieving source code.
If the shared library is loaded from SCM and your workspace path is jenkins/workspaces/jobName , then a copy is checked out to jenkins/workspaces/jobName@libs or similar (might be suffixed with a number if that path is occupied by another concurrent build).
In Jenkins, go to Manage Jenkins → Configure System. Under Global Pipeline Libraries, add a library with the following settings: Name: pipeline-library-demo. Default version: Specify a Git reference (branch or commit SHA), e.g. master.
Create a separate git repo for the Jenkins pipeline library & push the shared library code to that repo. Integrate the shared library repo in Jenkins under the Manage Jenkins section. Create Jenkinsfile in the project. In that Jenkinsfile, Import & use the shared library.
To ensure everything was reported in the right packages, without having to enumerate all the packages, I used:
mkdir -p doc/
groovydoc -d doc -private -nomainforscripts -sourcepath src:vars \
$(find src/ vars/ -name \*.groovy -printf '%P\n')
This incantation convinces Groovydoc to get the packages right without requiring me to tediously list them all, which is the main challenge.
If your find
doesn't have -printf
, replace -printf '%P\n'
with | cut -d '/' -f 2-
. The effect is the same; strip the leading src/
or vars/
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With