Using the Snippet Generator tool in Jenkins 2, I can setup a plugin like I would within a job, and then it will generate me the Groovy I can use in my Pipeline script.
But what if the plugin I am interested in instrumenting isn't listed in the "Sample Step" drop down in the Snippet Generator? How do I determine how to create a script block to instrument the plugin I want to use?
In my case, I would like to use the "Flexible Publish" plugin within my Pipeline script.
You can't use plugins which are not compatible with pipeline generally.
Plugins need to be modified more or less to be compatible.
See https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md
To be complete you need to know that snippet generator only shows compatible plugins that declare a specific help page in plugin's code. If we take the example of docker-workflow plugin, you can see in the code that it defines a help page for DockerDSL, which means that a Snippet Generator will be available for DockerDSL step.
Therefore you should always check Jenkins plugins compatibility page (as arasio mentionned it) and not what you see in Snippet Generator.
Related
How does one go about finding the documentation on Jenkinsfile configuration options provided by Jenkins and the plugins that are installed?
For example, to set the "Do not allow concurrent builds" option, I have to set properties([disableConcurrentBuilds()]). I don't see documentation on that option anywhere except under the documentation on declarative syntax.
For plugins, I have the Github plugin installed but I don't know how to find what the option is to check "GitHub hook trigger for GITScm polling". I don't see documentation on the plugin page or github page.
Do I need to dig into the source to find these options? If so, what am I looking for in the source?
I found it under the Pipeline Syntax generator. There's a sample step for properties that allows you to check all the boxes and will generate the relevant code for you.
Currently I have a multibranch pipeline job where a build happens and the cppcheck is used to analyse the code. However there is no 'post build actions' tab available available in the multibranch pipeline to enable 'publish cppcheck results'. I have been searching long in the internet for an answer but i am not able to find.
There are only General,Build Triggers,Advanced project options and pipeline tabs available ( i chechked the advanced project options and there is no option to add the post build section there).
Is there a way to hardcode the cppcheck.xml publish using the jenkinsfile itself? Is there any syntax that i can use that will call the cppcheck plugin to check the xml file and publish it. This is really an emergency requirement. I tried searching a lot to convert the xml to other formats like html or jnuit xml . Nothing seems to work. Can someone help?
To do that, I'm using the Jenkins Warnings Plugin with a custom parser.
Since release 3.8 you can define new parsers dynamically in the system configuration section of Jenkins. Just navigate to http://[jenkins-url]/configure and create a new parser in section Compiler Warnings. The UI should be self explanatory
Instead of XML, a text file is generated with this command line:
cppcheck --enable=all --template="{file},{line},{severity},{id},{message}" . 2> cppcheck.txt
Here is the help for the template parameter:
--template='<text>' Format the error messages. E.g.
'{file}:{line},{severity},{id},{message}' or
'{file}({line}):({severity}) {message}' or
'{callstack} {message}'
Pre-defined templates: gcc, vs, edit.
More information can be found in the Cppcheck PDF manual.
I'm using this regular expression to parse the file:
^(.+),(\d+),(error|warning|style|performance|portability|information),(.*),(.*)$
UPDATE
The Warnings Plugin reached end-of-life. All functionality has been integrated into the Warnings Next Generation Plugin.
With this new plugin, cppcheck is supported without the need of a custom parser.
Generate the XML file with this command line:
cppcheck --xml --xml-version=2 . 2> cppcheck.xml
In your Jenkinsfile you will need to add this line to scan the file for warnings or issues:
scanForIssues tool: cppCheck(pattern: 'cppcheck.xml')
Currently the CPPCheck plugin does not support pipeline.
There is however a pull request open for the plugin
https://github.com/jenkinsci/cppcheck-plugin/pull/36
Feel free to clone it and do some more testing.
In november 2017, the pull request mention by JamesD was merged.
If you look at the Pipeline documentation, there is now a htmlpublisher command.
Please note that the xml has to be previously generated and that the pattern argument used below search for the file from the %WORKSPACE% path.
stage('CppCheck') {
steps {
publishCppcheck pattern:'output/bin/Release/report_cppcheck.xml'
}
}
I am working on Jenkins pipeline for two projects. I built some customized configuration alerts messages via slack and emails. We expect my code can be used for my projects and also several other projects. So I am thinking to make it a small lib so that others don't need to ask me every time they onboard a Jenkins pipeline jobs. I was thinking using shared library with #Library() for other to use, as described in the docs.
However, since my lib depends on the existence of slack and emails plugin, it will not be usable when these plugin are not installed.
My question is: is there are way to declare dependency in pipeline Shared Libraries or I have to make jenkins plugin to address this issue?
As far as I know there is no way to declare dependencies to plugins right now (or version of Jenkins). Instead, what you can do is add a check for the plugin and give a proper error to the user of your library:
if (Jenkins.getInstance().getPluginManager().getPlugin("Slack+Plugin") == null) {
error "This shared library function requires "Slack plugin!"
}
Put this at the start of your shared library script, before any uses of the plugin. Note though, this gets tricky if you need to import classes from a plugin (since imports goes first in the groovy file). What you do in that situation is to make two scripts, the first script has the check and is the one the user calls, the second contains all the logic and imports, and is called by the first script once the checks pass.
I'm starting to work on pipelines for jenkins (formerly workflow)
I'm using IntelliJ for an IDE
Is there a source of Documentation for GDSL or some way I can know what groovy is acceptable in the pipeline and what is not?
Also is there a way that I can test run the GDSL before having to check in my Jenkinsfile?
Is there a source of Documentation for GDSL
Yes, as of 1.13 you can download a GDSL schema from Snippet Generator and install it in IDEA. There are some aspects missing—for example step return types are not defined in this schema. Last I checked it also did not offer completion on, for example, known $class implementations for step; this information is available in the Snippet Generator UI and downloadable HTML reference documentation.
is there a way that I can test run the [script?] before having to check in my Jenkinsfile?
There is not currently an offline test feature; it would be tricky since everything in a Pipeline script is intended to be interacting with a live Jenkins service. (If you have other logic in there, it would be better factored out into external scripts in the language of your choice.)
As of 1.14 there is a Replay link you can use to iteratively test proposed changes before committing to Jenkinsfile, and you can use this from the CLI too.
I have one bash/shell script to check a set of constraints in my project. The output of this script is the number of errors/violations found in the source code (Non Java project).
I'm looking for a Jenkins plugin to check this script output and notify a fail depending on a threshold. It's the same functionality as Violations plugin + Checkstyle, PMD, etc, but the datasource should be a custom script.
I have been searching for a while, but anything fits this requirement.
Do you know if this plugin exists?
You may want to look at the Warnings plugin, it describes how to "Write a new parser that should be included in the warnings plug-in" and to "Write a new standalone parser that will be deployed in a new plug-in"
It also have a "Failure threshold to mark a build as unstable"