Jenkins Auto-Configuration via Add-on
With an aim to help you to get the best usage experience and achieve the maximum possible automation of the DevOps approach at the Jelastic Platform, below we’ll reveal how the process of Jenkins CI server configuration can be greatly simplified.
To accomplish this, we’ll leverage a new solution, implemented by combining two progressive technologies: Jelastic pluggable add-ons and Cloud Scripting operations - the next generation mechanism for application and server management within the Cloud. In particular, such an integration allows to automatically create the complete list of job templates, which just need to be slightly tuned (with operations like setting a URL to the repository with the required project instead of the default one) to complete the Jenkins server adjustment.
The true efficiency of such an implementation is fully revealed in case of handling multiple projects, as instead of the countless step-by-step manual configurations, required for each of the Jenkins servers to be properly set, you’ll need to create a single add-on just once. Subsequently, it can be easily applied to the required environment in a few clicks with just several user-dependent parameters needed to be adjusted, saving an increasing amount time on each following installation.
Configuring Jenkins using Cloud Scripting
To designate the greatest part of the Jenkins server’s setting up to be performed automatically, the appropriate configurations should be written in a form of code lines firstly. Subsequently, they will be executed at your application server with Jenkins running. At Jelastic, this could be done through preparing a special JSON manifest file, which, being integrated to the platform, will represent a pluggable add-on, that can be easily run by any user directly through the dashboard.
Let’s start with composing the basis for our add-on in order to get the ability to apply it to the required Jelastic environment further:
- Log into your JCA panel as an administrator user and navigate to the Marketplace section using the main menu to the left.
Once inside, expand the Add list at the top pane and select the Add-on option.
- Within the opened editor, paste the general code template of the following structure:
The highlighted parameters should be substituted with the appropriate data - here you need to define the general information about your package and specify the operations it is intended to perform:
- package_name - add-on name it will be titled with at users' dashboard (e.g Jenkins Configurations)
- logo_url - link to the image that will be used as a package icon (you can use our default one through copying and specifying this URL)
- custom_code - list of comma-separated shell commands, that will be run on add-on’s appliance
Whilst the first two settings are obvious, the last one needs to be considered in details, thus the next section of the guide is devoted to delving into the specifics of the required operations' scripting.
In our example, the Jenkins integration tool is installed over Tomcat 7, so all the commands used would be based on its specifications. We intend to automate the process through scripting the following operations:
- uploading the scripts, required for setting Jenkins jobs
- configuring Jenkins itself
- creating and linking jobs to automatically lead an application through the lifecycle
Further, we’ll examine each of these points in more detail and prepare the core of our manifest according to this flow.
This could be done through adding a separate environment with the same topology your add-on is being created for (i.e. Tomcat 7 with Jenkins app deployed in our case) and running the adjusted below described commands directly inside your compute node’s container using SSH. If you need any assistance with this, please refer to the complete guidance on the DevOps Add-on for Jenkins Troubleshooting, which additionally includes descriptions of the expected results for each of the presented operations.
So, let’s reveal how the above suggested processes can be easily accomplished, with the help of the appropriate Cloud Scripting options. Subsequently, all of them need to be inserted instead of the custom_code parameter in the manifest example, in the same order they are described below.
- In the first piece of code, we create a dedicated projects' folder and fill it with the files, required for the further Jenkins jobs setting:
- /opt/tomcat/demo - the full path to the folder, where all of your management scripts and the related data will be stored (we’ll use demo, but you could create and use any other desired directory - just don’t forget to specify the correct path everywhere throughout your code)
- the variables file, created at the 3d string, is intended to be used for further storing of the automatically generated name for your environments
- curl -fsSL file_url -o file_name - this command initiates scripts uploading inside the container (for the detailed information on the needed scripts preparation, please get acquainted with the corresponding guidance)
- The second part of code will remove all the existing (i.e. that are installed automatically during the initial tool deployment) Jenkins plugins in order to prevent incompatibility issues or mismatch of their versions with the upcoming configurations:
- After that, you need to move to the main .jenkins directory and add the necessary plugins and configuration files to the Jenkins integrator instead of the deleted ones, by uploading and extracting the appropriate plugins.zip archive.
- The next section of the code uploads and extracts another required package (jobs.zip), that will set Jenkins jobs according to the data inside.
The archive structure should be the following:
- one general jobs folder, which may include multiple directories, named after the appropriate comprised jobs
- each of such directories should contain the config.xml file (with all the required configs specified inside) and the builds folder with an empty legacyIds file
We’ve already prepared such an archive, which contains settings for creation of the jobs, devoted to each step of the proposed application lifecycle flow:
Create Environment > Build and Deploy > Dev Tests > Migrate to QA > QA Tests > Migrate to Production
Everything else may remain as is; however, you can also edit it or add your own jobs if needed.
- Finally, define the restart of the server in order to apply all of the executed configs.
Being combined together, all these code parts will automatically perform almost all the required Jenkins configurations.
Thus, now you can place them within the appropriate commands manifest section as it was suggested above - you’ll get something similar to the following:
Enabling the Add-On
To make our module accessible via the dashboard, find and select it within the list, click on the Publish button above and confirm this action at the shown pop-up.
Everything is prepared now, so let’s just see how quick and simple the implementation of our DevOps approach becomes now.