jenkins plugin to validate patches? - jenkins

I have seen a few open source projects validate patches before commiting. They would have checks like "does this patch add tests?". I am having a hard time finding a plugin that would let me test a new git patch and validate that it adds what we require to a patch.
What jenkins plugins will let me validate patches before they go into a build?

The best way to do this is to start using Gerrit code review. This together with the Gerrit plugin for Jenkins will make it a breeze to do what you want.

Related

Jenkins-Gerrit Integration: It is possible to attach a file to a gerrit comment?

Currently I have a CI/CD using jenkins and gerrit. I already have the jenkins and gerrit communicating using the Gerrit Trigger Plugin. I am able to increase and decrease labels like the Code-Review one and I am also able to send comments to gerrit. To configure this I use the following UI's:
I want to know if there is a way to add some file to that comments. Because I have a few tests running in the pipeline. In the end a report file is created and I would like to added it to the comments in the gerrit change that trigerred the build.
I know that one easier solution would be just store the report has a artifactory and then pass the link to the artifactory in the message.
Other stuff that might be important:
Jenkins v2.375.2
Gerrit v3.7.0
Gerrit Trigger Plugin v2.38.1
Gerrit Code Review Plugin v0.4.7
This is basically what I have:
source of the image
I tried to use the following command in my Jenkinsfile.
stage('Test'){
steps {
gerritComment(path: "./report", message: "This is a sample comment.")
}
}
Gerrit returns me Method not allowed.

pre-commit check or Remote-run missing with Github setup & Jenkins

Just to quote as an example one can submit a remote-run with some tool like TeamCity (similar to Jenkins) where it will apply delta/patch on what user is trying to commit & produces result whether changes is good from set-of configured checks for that project.
With Github & Jenkins, can such validation be achieved with any plugins out there?, which will avoid breaking a build?
I know with pull-request & status check one can achieve similar end-result. But without commit/push to remote repo of Git - is there a way Jenkins can handle this validation & produce initial result ??
It isn't possible to have GitHub perform checks on data it doesn't have, so if you don't push the data to the remote server, GitHub won't know anything about it and therefore will do nothing.
Jenkins does have a REST API that you could use to do this, provided you equipped each developer with appropriate credentials. However, this is not a common situation and wouldn't be a recommended configuration.
You'd be better off with a script in the repository that users could install as a hook or invoke from a hook that would perform the testing you want. If your CI jobs run a script in your repository, then sharing code between them should be easy.
Note that you shouldn't mandate pre-commit hooks, since they can interfere with advanced users (who may make intentionally incomplete temporary commits) and they can be disabled by users. Any sort of required checks should be done as part of CI, where policy can be enforced appropriately.

Jenkins Github Organization exclude commits from certain users

Using a Github Organizations folder, is there a way to prevent a pipeline from running if a commit is submitted by a specific user?
As a first step of your pipeline, you could use git to get the name of the author of HEAD.
Fail or skip the rest of the pipeline, if it is your special user.

hudson: way to get the user value who initiated the build?

Is there a way to get the hudson job initiated user name.
Is it possible to get using script shell, py etc.
Lets assume I have the build # which was initiated. I know how to get the latest build info using api but would like to get a user details for a specific job.
Do you think, this will work for hudson? :)
https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin
Thanks in advance
That plugin will not work with Hudson, unless you download a very old version of the plugin. I'm not sure how many people are still using Hudson and haven't upgraded to Jenkins.
Anyway, when a user manually triggers a build, this is called a "user cause"; there are other types of cause, e.g. SCM trigger.
You can use the JSON or XML API to get the causes for a build, for example:
https://ci.jenkins-ci.org/job/remoting/lastSuccessfulBuild/api/xml?xpath=//action/cause/userId
In this case, this returns the username that caused the build to run.
Though note that there may be multiple causes for a build, and potentially other cause types that use the userId field.
This works in Jenkins, but it should also work in Hudson, but I haven't tested it.

Disabling and enabling jobs in jenkins

Currently in order to enable or disable a job, a user must have Job Configure permissions in the Matrix-based security configuration.We would like to be able to manage the enable / disable job permission independently from the job configure permission.
There are some nightly jobs that we want every user to be able to enable and disable the project without touching/breaking the configuration.
Thanks
Provide a script for the users that will do this using the credentials of 'root' user and set only the execute bit on the script so that no one can read/copy it.
At least 3 ways to make a script:
HTTP POST request:
1.
curl -X POST http(s)://<your_jenkins_url>/jenkins/job/<nightly-build_job_name>/disable
2.
Use python JenkinsAPI.
Documentation is very good, easy to understand much like the API.
3.
The third one can be a script which will use jenkins-cli: accepted answer describes this well .
The Job Configure permission is bounded to the disable/enable function in each job, that's true.
One alternative to disable/enable jobs without the corresponding permission is to create new jobs which do this internally. For example, a job that needs job names as parameters, and disables them.
You could use curl + credentials of a Jenkins user with the Job Configure permission.
You could use plugins. For example, this script using the Job DSL Plugin:
job("jobname"){
using("jobname")
disabled(true)
}
For other options, check out this question.
You may try to install this plugin to get the enable/disable button for the individual project-
I checked in my Jenkins and I could see this:
But when I checked under plugins section I don't see this extra column plugin installed. Probably this is the default behavior in latest versions of Jenkins.

Resources