Preparing Management Scripts

In order to achieve the automatic development flow, Jenkins requires special instructions, that indicate what should be done during different application delivery stages. In our case, we’ll define the necessary actions within special scripts (one for each required operation), to easily call these complex processes by means of Jenkins jobs afterwards.

In such a way, the next step is to create and upload the appropriate scripts to the Jenkins container:

1. To start with, here is a set of script examples, which can be used as templates for your own ones:

  • install.sh - gets a user session and creates a new environment via the Jelastic API according to the specified manifest file. It also defines, that the name of this environment will be equal to its creation date and time (as a unique name is required for every script execution, but you won’t be able to set it manually as this operation would be run automatically). However, you can set your own dynamic name pattern to be used here

  • transfer.sh - changes the environment ownership based on the Jelastic environment transferring feature

  • migrate.sh - physically moves an environment to another hardware set (hardnode group)

Note: Before the appliance, each of the script templates, presented above, have to be additionally adjusted to make them work properly within a particular Jelastic installation. Thus, the list of parameters below should be obligatory substituted according to your platform’s settings:
  • /path/to/scripts/ - the full path to the folder with your scripts (see the next step)
  • {cloud_domain} - your Jelastic Platform domain name
  • {JCA_dashboard_appID} - your dashboard ID, that could be seen within the Platform.DASHBOARD_APPID parameter at the JCA > About section
  • {JCA_appstore_appID} - appstore ID, listed within the same section (at the Platform.APPSTORE_APPID parameter)
  • {url_to_manifest} - link to the JPS manifest file created according to our documentation (you may also use this one as an example - it sets up two Tomcat application servers with the NGINX load-balancer in front of them)

2. When the scripts are ready, you need to upload them to the Jenkins container. The easiest way to do this is to establish connection via the Jelastic SSH-gateway.

In the case you haven’t performed similar operations before, you need to:

Once inside, create a new folder for your project (we’ll use demo) and move in there:

mkdir /opt/tomcat/demo
cd /opt/tomcat/demo

This location can be used for storing your scripts, variables, logs etc.

3. Here, you can upload the required scripts using the command of the following type:

curl -fsSL {link_to_script} -o {file_name}

Note: Above, you can see one more (i.e. not listed in the first step) runtest.sh script uploaded - it simulates the testing activities for demostration purposes, thus we don’t provide its code in this tutorial. If required, create your own one according the specifics of your application and upload it alongside the rest of the scripts.

4. In addition, you need to create a separate file for storing the variable with environment name (as it needs to be dynamically changed each time a new environment is created):

echo ENV_NAME= > /opt/tomcat/demo/variables

Now all the preparations are finished, so we can proceed to the core of automation - configure the set of jobs at the Jenkins server.