I want to setup groovy to dismiss all warnings. I found the posting to setup jenkins groovy for security warnings. But I did not find three ids of that warnings:
enter image description here
Have I to take another ways to dismiss that warnings?
Those warnings are Administrative Monitor warnings.
Jenkins > Manage Jenkins > Configure System > Administrative monitors configuration. Click on the Administrative monitors button. (Example)
Disable any warnings with caution.
If using JCasC, you can add steps to disable.
You can achieve the same using groovy and groovy.init.
Related
I have a significant amount of pre-configuration that I want to automate for Jenkins. E.g. Pre configuring gerrit for the gerrit trigger plugins, pre configuring saml, libraries etc
I'm aware of two methods typically used to do similar tasks:
Configuration as code plugin + yaml configuration
Groovy scripts to execute from the init.groovy.d directory of jenkins home on Jenkins startup
My users want to be able to update Jenkins configuration from the UI without needing to update yaml, suggesting the config as code plugin isn't fit for our purpose as I believe it reapplies the config when the Jenkins container is restarted.
My hunch is to use groovy scripts that remove themselves after the first execution so that they don't reapply themselves on restart.
Is there a more standard way of pre configuring Jenkins? or is groovy my best bet?
TL;DR: Use the file system
Why? There is no "standard" way to achieve what you intend; the two approaches that you suggest are viable options for sure.
From operational point of view, however, it will be good to select a solution which is
generic (so it can cover all aspects of Jenkins configuration) and
"simple" to use
Now,
"Configuration as code" makes you depend on the corresponding plugin -- it may or may not support a specific configuration option
With groovy, it is sometimes quite difficult to find out how to set a Jenkins configuration option (and how to store the setting permanently).
Since all Jenkins configuration data is stored on-disk, another option for bootstrapping Jenkins with a well-defined configuration is to pre-fill those configuration files with proper content right away:
You can be sure that this works in all cases, including all border cases (like, secret/encrypyted data)
Users can change the data later on as needed
Usually, it's quite easy to find the proper configuration file
On the downside, there is a risk that the configuration file format might change with newer versions of the core or of some plugin. However, a similar risk exists for the two other solutions that you suggested.
Tip: for rolling out such pre-configured Jenkins setups, it is helpful to disable the Jenkins setup wizard by setting jenkins.install.runSetupWizard to false.
When you combine words like : pre-configuring Jenkins, init.groovy.d, jenkins home, jenkins startup, etc, it sounds confusing o_O
When Jenkins is ready to use, usual folks just need to create jobs or pipelines. If you need to create a job or pipeline, you just need to install and configure some plugins. Very few of them need groovy, because the goal is "Easy to use".
Advanced user are able to create its own plugins, with java. But almost all is available as plugins.
You can use groovy in a pipeline scripts or declarative pipelines.
So if your question is more like "What is the best way to create and configure jobs or pipelines", I can advise you:
Try much as possible to use pipeline scripts or declarative pipelines.
Use just verified and supported plugins.
Stop call shell scripts in hard drive.
Stop using complicated configurations. Almost all of requirements are already implemented and documented.
If you have a requirement and no one plugin seems to help you, ask here in stackoverflow or develop your own plugin focused in configurability, so you can release it, for the benefit of Jenkins Community.
I added Warnings plugin to Jenkins (2.138.2) but I don't see the post build actions of the warning plugin.
I see "Scan for compiler warnings" and many other actions, but not "Record static analysis results"
What may be the problem?
I also had the same problem. For me it was enough to refresh the page after building the project. It should look like:
I want to treat warnings as errors in Jenkins, but not when I build locally. So I can't just enable it from the project settings because that would apply locally as well. I also don't want to use a separate configuration, I want to build in Debug for Jenkins.
That leaves specifying it as a command line parameter when running msbuild, how can I do that?
I think you should take a look to the Warnings Plugin of Jenkins. It is specifically done to parse ("standards") compiler output and group/count warnings. It can also mark your build failed if too many warnings appeared (with the support of the generic Static Code analysis plugin).
You can configure the health of your build according to the number of warnings detected (first line in the following picture). Health will not fail the build, just change the weather associated (sunny, cloudy, rainy... ;) ).
To change the state of the build, this will be done in the last lines of the following picture. In my configuration, if more than 10 warnings are found, builmd will become Unstable, and more than 100 will fail the build. Adjust the values for your needs ;)
Warnings plugin configuration
Is there an easy way in Jenkins to list all all builds marked as keep-forever? And then, ideally, one click to either unmark the build as keep-forever or to immediately delete it?
In our process, we mark a build as keep-forever if it involves some specific type of failure; that's to keep Jenkins from automatically deleting over time. I need an easy way to get a list of all those keep-forever builds so they don't take up all our disk space over time.
The following XPath query against Jenkins will list the URLs of all builds marked 'Keep Forever':
http://[jenkins_server]/api/xml?depth=2&xpath=/hudson/job/build[keepLog="true"]/url&wrapper=forever
Enter it in the browser and see what it returns.
Now, you can embed it into XSLT-based HTML to get a list with links to those builds. To delete the build you can provide a button that invokes Jenkins CLI:
java -jar jenkins-cli.jar -s http://[jenkins_server]/ delete-builds [job-name] [build-num]
Unfortunately, I do not know how to disable 'keep build forever' with CLI without deleting it.
I was looking for the same thing, and our jenkins is pretty big as well and trying the link:
http://[jenkins_server]/api/xml?depth=2&xpath=/hudson/job/build[keepLog="true"]/url&wrapper=forever
I ended up crashing it.
But as it turns out I only require the last 'keep forever' build of one job at a time, which seems to work way faster. So I use the following instead:
http://[jenkisn_server]/job/[job_name]/api/xml/?depth=2&xpath=/freeStyleProject/build[keepLog="true"]/number&wrapper=forever
which returns the xml with all the numbers of build that are marked as 'keep forever'
You can modify the xpath to fit your needs.
Our team is sharing a Jenkins server with other teams, and this currently means that we are sharing the same OS-level build-user account. The different teams' OS-level build-user settings (Maven settings, bash settings, user-level Ant libraries, etc...) have collided a few times--"fixing" the settings for one team's jobs inadvertently "breaks" another team's jobs. The easiest sol'n that occurs to me is giving each team its own OS-level build-user account with which to execute its Jenkins jobs--but I cannot find a way to do this.
I have checked with Google, and also here
https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins
and here
https://wiki.jenkins-ci.org/display/JENKINS/Plugins
to no avail.
Is there a way to do this? If not, can you recommend any best practices for segregating sets of builds from one another?
Maven Specific
You have two options that come to mind,
Add additional installations of Maven into your Jenkins global configuration, each using their own Home directory, and thus settings files. This will allow you to use totally different version of Maven, and selected based on Job requirements (You are given the option to select which "version" of maven you wish to use on the job itself.
Similar to (1), but specify specific settings configurations using Maven command line arguments. Its a little less "obvious" but may be quicker to implement
Multi-slave
You could possibly make use of multiple slaves on each machine. It increases the overheads of the builds quite significantly, and the implementation is such that you'd have multiple user accounts on a machine, each setup as needed, and then one slave instance for each user.
I'm not sure these solutions will totally answer your problem, I'll have a think and see if anything else pops into mind, but it might give some starting points
Key builds to a specific team directory that contains that team's settings. For example, provide a parameter 'TEAM' to every build, set its default value to the appropriate team name, and use that parameter as a key to a directory that contains the team's settings (so instead of using ${HOME} as in what you want to do, you'll use something like ${TEAM_SETTINGS}/${TEAM}).
You can set per-job users (who has access to/can build a particular job).
Under "Manage Jenkins" > "Configure System" >
Click on Enable Security
Check Project-based Matrix Authorization Strategy
However, I do not think there is a "per-build" option for a single job.
If you have the same project that you are sharing between teams, you could (and probably should) create two jobs for this project, and have different libraries/scripts be used in each.
You could also parametrize the build (On the Job Page, "Configure" > This build is parametrized) and supply the library versions, etc via string parameters.
You could also use a parameter to be the team's name, and in your build script change libraries based on the parameter:
For example, have a parameter called "TEAM", with choices: TEAM_A and TEAM_B, and in your script, have
if [ $TEAM == "TEAM_A" ]
then
ANT_HOME=/opt/ant/libA
else
ANT_HOME=/opt/ant/libB
fi
======================================================================
Have you considered sourcing your settings? In Linux, you could do this by saving your OS settings in a script file (for example paths, etc), and using source /path/to/settings/file, in Windows it would be call /path/to/settings/batch/file.
Can you give examples of OS level settings that you would require and per-build user for?
You problem is a common one.
Whenever something nonstandard is installed on a build server, something will break for someone.
The only solutions I know are
Set up a separate build slave for each team or product. Then they can install whatever they want on the build slave and any mess they create is all their own fault.
Any dependencies required by a job need to come with the job. This is my preferred way of working. For example: If a job needs a library or a tool, the library or tool is not installed on the build server but in the source tree and the build uses it from the source tree.
Sometimes the latter way is more work. You need to set up the tools or library so it works when it is installed in the source tree. Some tools have hard-coded paths and they do not work. In that case you can install the source of the tool and compile the tool during the build.
An even better solution is to set up separate Jenkins jobs for all the tools and libraries and the jobs that need a library or tool will download them from the Jenkins jobs.
This way you can control all your dependencies and different jobs do not conflict when e.g. one needs an older version of a library and one a newer version. And if someone upgrades the library, it is immediately visible in the version control who did what.