I started implement Jenkins shared libraries and trying to write my jenkinsfile with intellij as my ide.
How do I get functions from the shared lib repository to the other repository which holds the jenkins file inside it.
Just to clarify things are working for me when running from jenkins but I need an easy way to write my jenkins file with the usage of functions from the shared-lib repo.
You can try using the IntelliJ IDEA GDSL file provided by Jenkins in your IDE.
Download the content from http://<JENKINS>/job/<PIPELINE_JOB>/pipeline-syntax/gdsl
to a pipline.gdsl
file and add this file to your IntelliJ Jenkins Pipeline project's source folder.
(You may also want to add that file to your SCMs ignore-list.)
Autocompletion before and after adding GDSL file:
On the Jenkins UI you find that GDSL file in your pipeline project under "Pipeline Syntax > IntelliJ IDEA GDSL".
However, I found some caveats with this solution that required me to manually edit the pipeline.gdsl
file, but that could be related to my not up-to-date Jenkins installation (?):
/var
folder) are considered in the GDSL file, but methods defined on that variable are not.
parallel
step was not exported properly due to an error(?) on the ParallelStep
class(Source of knowledge: Veaceslav Gaidarji's blog.)
I have had good experiences with jenkins-pipeline-shared-libraries-gradle-plugin by mkobit in combination with IntelliJ IDEA.
Some great features of this plugin are
Personally, I develop my pipelines in the shared lib project and integrate the pipeline into the target repository after passing the unit tests.
There is also an example repository for a demonstration of using this plugin.
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