Jenkins Plugin installation with chef cookbook - jenkins

I got a task to create a (chef) cookbook that should install jenkins plugins.
Note: when i apply the cookbook it should install it automatically.
Thanks in advance.

There is a jenkins cookbook that does this very well (look at the "jenkins_plugin" section)

The Chef public Supermarket cookbook can be found here. If I was you, I would use that as the base for the functionality you require.
Create a new cookbook which depends on the public Jenkins cookbook
(this will cause your new cookbook to inherit all functionality
found in the public cookbook).
Create a new recipe in your new cookbook which specifies which
plugins to be installed when Jenkins is installed / configured. See the Jenkins_Job section of the Chef Supermarket Jenkins cookbook for additional details.
Note: In order to find the correct .HPI file location for the version of the plugin you want to download, you can look at the Jenkins Wiki page for each plugin, and using the link to the archives of all releases of that plugin find a suitable link for the version you wish to install.
An additional step that I personally take is to write some automated tests to run against the plugin installation / configuration using Chef's test-kitchen:
What I do is find the filepath for the particular plugin you want to
verify has been installed, and write a test confirming that the
filepath exists.
An additional test I also write for each plugin is to parse the
pom.xml configuration file found within the directory in order to
verify that the correct version has been installed (in the event the
link to the specific release available on the Jenkins Wiki is giving
you the incorrect version).
And last but not least; I strongly recommend you use Berkshelf to manage your cookbook dependencies. If you go this route, it will be critical that you create your own cookbook which depends on the public cookbook so as you are able to upgrade your public cookbooks using Berkshelf without issue.
If not, all your custom configuration for plugins you have added to your copy of the public supermarket cookbook will be overwritten when you upgrade your public cookbook to the newest version when it's released.
Best of luck and please post any additional questions here!

Related

Jenkins plugin updates are unavailable

I have updated my jenkins server and see the following message for some plugins. I am not sure how to fix this. I looked at the dependencies section for that plugin and I see they are already installed. Not sure what else is missing so I can see the update available. Dependency for this is Mailer which is already installed on my server.
That is frustrating but you can try uploading plugins manually.
You can download plugins from here link to plugin storage.
Of course you have to roughly see what version of the plugin goes with your jenkins version.
Once you downloaded 'proper' plugin version, you go to manage plugins, advanced tab and there you can upload the plugin file. After that restart jenkins and check changes. You should really go to manage plugins, updated plugin tab and update selected plugins...
It could be guess work, but I'm sure after a couple of guesses you'll get to the version of Jenkins you have.
You might need to upgrade jenkins.. here are all jenkins war files:
https://get.jenkins.io/war-stable/
Last but not least... don't try to fix all dependencies.. fix those you use, rest is optional.

How to install jenkins plugin using chef?

Currently jenkins does not have a proxy setup and I need to install a Jenkins plugin.
I am looking for some pointers in doing so using Chef.
Have a look at the jenkins cookbook from Chef supermarket.
Once you add the appropriate dependency in your cookbook. Then you can use this cookbook's jenkins_plugin resource to manage plugins. Example to install a plugin named myplugin:
jenkins_plugin 'myplugin' do
version '1.0'
end

Jenkins plugins for old versions

Fore some reasons I have to use Jenkins 2.32 and I need to install some plugins there. Machine with it has no internet, so I only can upload plugin file to install it from file.
So, the problem is there any easy way to obtain required plugin for required Jenkins version with all it's dependencies?
p.s.
I can't update Jenkins - it's out of my power.
p.p.s.
I find only way to download old versions of plugin, but by this way I can't check dependencies and required jenkins version before loading.
I had such an environment before.
Warning: it's an annoying process.
Because there was no internet, we uploaded all plugins manually, i.e. looking at the plugin page (e.g. https://plugins.jenkins.io/git/) and then downloading from the archive (e.g. https://updates.jenkins.io/download/plugins/git) the .hpi file. As you have to use a relatively old version of Jenkins you may want to check the changelog of the plugin, if you have to use an older version.
In addition on each plugin page the dependencies are listed and you have to repeat the above steps for each dependency.
The only good thing is that usually Jenkins gives you hints, which dependencies are missing after you uploaded a plugin.
You can probably extract the information out of the plugin-versions.json in the Jenkins Update Center.
For more information about the layout of update center, see this document.
You may also find my previous response on jenkins failed to install plugins - docker image (with groovy scripts) helpful

Using Jenkins CLI to configure plugins

I am working on installing and configuring Jenkins automatically using the Jenkins CLI. I am able to install plugins such as the Active Directory plugin, but haven't figured out how to configure it. Is it possible to perform such tasks from the CLI? From a Jenkins GUI standpoint, I'd like to check the Enable security checkbox under Security Realm check the Active Directory option, provide parameters to Active Directory, and under Authorization check the Anyone can do anything option.
I'm using a Puppet module (https://forge.puppetlabs.com/rtyler/jenkins) for the automation.
Greetings,
Kenneth
If you want to modify their configuration files manually using scripts called from the CLI, then yes.
Else, I don't believe there is. At least, not a general way for all plugins. Plugins are capable of adding CLI commands, as per this documentation page:
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
Extending CLI
Plugins installed on Jenkins server can add custom CLI commands. See Writing CLI commands for more details.
So, some of the plugins you're using may have specific commands to configure them from the CLI.
So as far as I know those are your options. Manual configuration through editing their config files, or hoping your plugin includes some commands in the CLI that is specific to it.
There is currently a new Plugin in development called "Configuration as Code Plugin" to provide a way for configuration of plugins using YAML: https://github.com/jenkinsci/configuration-as-code-plugin/
They are currently in an early development stage but this could help solve this kind of problem.

Updating jenkins plugin from source

I currently have Build User Vars Plugin 1.1 installed in my Jenkins. Since version 1.1 of the plugin, there has been some important changes to the plugin code, and I want to pick them up. The question is what is the least amount of work to package up the hpi/jpi file that I can push on my Jenkins install that will contain latest changes.
It's fairly easy to build a plugin locally; you can then upload the hpi/jpi file to Jenkins via the Advanced tab in the plugin manager.
See the Jenkins plugin tutorial for detailed steps.

Resources