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:
Further, we’ll examine each of these points in more detail and prepare the core of our manifest according to this flow.
Note: Below we provide you with the example code, which needs to be modified according to the specifics of your application. In order to ensure this was done correctly and all of the actions were scripted properly, we recommend a preliminary test of your code.
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.
1. 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:
"echo ENV_NAME= > /opt/tomcat/demo/variables",
"curl -fsSL file_url -o install.sh",
"curl -fsSL file_url -o transfer.sh",
"curl -fsSL file_url -o migrate.sh",
"curl -fsSL file_url -o runtest.sh",
2. 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:
"rm -rf /opt/tomcat/temp/.jenkins/plugins",
3. 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.
"curl -fsSL file_url -o plugins.zip",
"unzip -o plugins.zip >/dev/null 2>&1",
We recommend to use the package
we’ve prepared for this example, which already contains all the necessary modules. However, you can complement it with other plugins if necessary or just pack your own zip archive - in this case, note that there are several obligatory tools it should comprise (namely: SCM API Plugin, GIT plugin, GIT client plugin, Environment File Plugin
) and all of them should be put in the plugins
folder inside the archive.
4. The next section of the code uploads and extracts another required package (jobs.zip), that will set Jenkins jobs according to the data inside.
"curl -fsSL file_url -o jobs.zip",
"unzip -o jobs.zip >/dev/null 2>&1",
The archive structure should be the following:
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
Note that in case you are using your custom path to the scripts folder, you need to edit the Build and Deploy job in our example package, as it contains the defined location of the file inside that directory:
Everything else may remain as is; however, you can also edit it or add your own jobs if needed.
5. Finally, define the restart of the server in order to apply all of the executed configs.
"sudo /etc/init.d/tomcat restart >/dev/null 2>&1"
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:
Click Save to finish and append your add-on to the list of the already available installations.