jenkins threshold plugin shell script - jenkins

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"

Related

Robot framework plugin does not show-up in Jenkins

installed the latest version of Jenkins 2.271
https://www.jenkins.io/download/
then installed the Robot framework plugin: https://plugins.jenkins.io/robot/#releases
2.12
Then when adding a new step after build attempt it should show all the options of the plugin.
But it doesn't do that, what can be the cause, I am clueless now...
I don't know the reason but after trying to use the E-mail notification (an smpt error came up, but that is not the issue here)
suddenly there was another option: Publish Robot framework test results
and that fixed it:
concluding: can Java open source work with the plugin?: apparently yes. (good to know)
What caused the option 'Publish Robot Framework test results not showing? unclear!
Somehow triggering the E-mail Notification (remember? : which became available after the Matrix multi project plugin) solved the problem and the left pane options also showed in the menu at that point.
It's a poorly named plugin: should be Robot Framework Publisher. If you read the Configuration section of the plugin, you'll see:
Select: Build -> Add build step -> execute shell/Execute Windows batch command
Add the command to run the tests. You might have direct robot/jybot command here like robot --variable name:value --outputdir my_robot_results my_test_suite or in case you need to do something
more, you can call any script that you use for running the tests.
Relevant part from Robot Jenkins Plugin point of view is that this
script generates the Robot outputs.
Force your Robot script to return successfully from shell with exit 0 to empower the plugin in deciding if the build is success/failure
(by default Robot exits with error code when there's any failed
tests). You can do this for example by adding --nostatusrc to your
test run (see Robot Framework user guide for details).
Select: Post-build Actions -> Publish Robot Framework test results
Thus you will only see a robot entry in the Post-build step to gather the results.
Note: JENKINS-36954 and OP's comments suggests you must also add matrix-project, which as of v.2.1.2 remains declared as "Optional" but appears to be required.
Update (2012-12-17): It would appear JENKINS-36954 is the culprit. I added steps to reproduce on the ticket, proposed sol'n, which has been accepted and PR has been merged. Expect to see it resolved in v.2.1.3.

How can i make the cppcheck.xml to be published on jenkins using the jenkinsfile itself?

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'
}
}

How can I share source code across many nodes in a Jenkins pipeline job?

I have a build that's currently using the old build flow plugin that I'm trying to convert to pipeline.
This build can be massively parallelized (many units of work can run on many different nodes) but we only want to extract the source code once at the beginning, preferably with the Pipeline script from SCM option. I'm at a loss to understand how I can share the source extract (which apparently is on the master) with all of the "downstream" nodes that will be used by the pipeline script.
For build flow we extracted to a well-known location on a shared file system and all of the downstream jobs invoked by the flow were passed (or could derive) that location. That always felt icky & I was hoping that pipeline would have solved this problem but I can't find anything to suggest that it has. What am I missing?
I believe the official recommendation for this is to make bundles of the source and then use "stash" and "unstash" to make them available to deeper steps of your pipeline script.
See https://www.cloudbees.com/blog/parallelism-and-distributed-builds-jenkins
Keep in mind that this doesn't do anything to help with line-endings. If you have builds that span OSs with different line endings you either need to make OS-specific stashes, or just checkout to a safe label in each downstream step.
After further research it seems like the External Workspace Manager Plugin does what I'm looking for.

pipeline Source for DSL

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.

Manually failing a build after it's complete

Is it possible to set the build result for a build after that build is complete?
I could not find any plugins that do this already, and I was considering writing my own, but I wanted to see if this was even possible before going down that path.
(I have looked at existing code and how the "Fail The Build" plugin works as an example, but my understanding of the Jenkins code base is not advanced enough to understand what all the possibilities are.)
Use case: we have a build pipeline, and near the end of the pipeline there is a deploy-to-qa step that deploys the artifact to a QA environment. We have automated tests before this step to try to catch any problems with the artifact, but our test coverage is not very high in some areas so bugs could still slip through the cracks. I'd like to have the ability to mark a deploy-to-qa build as FAILED after the fact, to denote that that particular pipeline was invalid and is not a candidate for production release. (Basically the same as this Build Pipeline Plugin issue)
After some more investigation in the code, I believe that this is not possible.
From hudson.model.Run:
public void setResult(Result r) {
// state can change only when we are building
assert state==State.BUILDING;
// snip
...
}
So the build result cannot change except when in "building" state.
I could try to muck with the lastSuccessful and lastStable symlinks (as is done with the delete() function in hudson.model.AbstractBuild), but then those would be reset as soon as Jenkins reloaded the build results from jobs/JOBNAME/builds/.
I have an untested suggestion: Make a parametrized build, where the parameter determines if build will fail or not (for example simple bat / shell script testing the parameter from the environment variable it sets, and doing exit 0 or exit 1). This assumes that build pipelines manually triggered step will ask the parameters, and not use default values.
If it does not support interactive build parameters, then some other way is needed to tell this extra build step wether it should fail or not. Maybe editing upstream build description or display name to indicate failure, and then allowing build pipeline to continue to this extra build step, which probably has to use system groovy script to dig out upstream build description or display name.
I have seen several debates on this topic previously, and the outcome was always that it is theoretically possible to do so, but the codebase is not designed to allow this and it would have to be a very hacky workaround.
It's also been said that this is a bad practice in general, although I don't remember what the argument against it was.
I am facing the same requirement. I haven't found an appropriate plugin, changing the build status is not just a flag but has other impacts on links (eg latest successful build etc). So instead of changing the status of the build I looked for a possibility for qualifying the build. The Promoted Builds Plugin apply flags to build to define e.g. different quality stages. Build promotions can be performed manually or based on e.g. downstream project successful builds. Any successful build can be qualified, based on the promotion additional build and post build actions can be executed, e.g tagging or archiving.
Actually I was able to do it by changing the build.xml manually to <result>FAILURE</result>.
I've then played a little bit with mklink to create some symbolic links and also renamed the lastSuccessfulBuild to lastFailedBuild and it worked. If you are allowed to access the filesystem from within a Jenkins PlugIn, then it is possible to write one.
In case you are fine to delete the current build and start the same build using a version number and setting the next BUILD_NUMBER to the deleted one, then you could use this plugin to tell it to fail instead of succeed:
Fail The Build Plugin

Resources