Build the Queue Trigger & PIPE Trigger for WFP-01-01-02

The Production Centre uses Docker images and deploys them in a Cloud based environment for large scale production campaigns.

This notebook will trigger the build of a Docker image containing the trigger.

We will invoke components of the Ellip Platform Continuous Integration.

The input for trigering the build of Docker image containing the data transformation application uses the pom, an XML file that contains information about the data transformation application and configuration details used by Maven to build the Docker image.

The goal of this Jupyter Notebook is to build of the data transformation application Docker image.

  • A few Python modules to do the job:
In [1]:
import os
import time

import jenkins

from nbconvert.preprocessors import ExecutePreprocessor, CellExecutionError
import nbformat as nbf
  • Read the data transformation application information
In [2]:
%store -r

nb_config = os.path.join('..', 'configuration.ipynb')

nb = nbf.read(nb_config, 4)

exec(nb['cells'][1]['source']) in globals(), locals()


In [3]:
trigger_queue_artifact_id
Out[3]:
'tg-wfp-01-01-02-queue'
  • Create two simple functions to submit the build request and to monitor it:
In [4]:
def submit_build_job(server, job, sleep_secs=3):

    last_build = server.get_job_info(job)['lastCompletedBuild']['number']

    server.build_job(job)

    while server.get_job_info(job)['lastBuild']['number'] == last_build:

        time.sleep(sleep_secs)

    return server.get_job_info(job)['lastBuild']['number']
In [5]:
def monitor_build_job(server, job, sleep_secs=15):

    last_build_number = server.get_job_info(job)['lastBuild']['number']

    while server.get_build_info(job, last_build_number)['building']:

        time.sleep(sleep_secs)

    if str(server.get_build_info(job, last_build_number)['result']) == 'SUCCESS':

        return True

    if str(server.get_build_info(job, last_build_number)['result']) == 'FAILURE':

        return False
  • Establish a connection with the build component of the Ellip Platform Continuous Integration:
In [6]:
server = jenkins.Jenkins(url=jenkins_url,
                         username=jenkins_username,
                         password=jenkins_api_key)

Build Trigger Queue

In [7]:
trigger_queue = dict([('artifact_id', trigger_queue_artifact_id),
                      ('repository', repository),
                      ('folder', folder),
                      ('community', community)])
print(trigger_queue)
{'community': 'ec-better', 'folder': 'wfp', 'artifact_id': 'tg-wfp-01-01-02-queue', 'repository': 'Gitlab Groups'}
In [8]:
job = 'communities/%s/%s/%s/triggers/%s/docker' % (trigger_queue['repository'],
                                                       trigger_queue['community'],
                                                       trigger_queue['folder'],
                                                       trigger_queue['artifact_id'])

print 'Submit build for job %s...' % job

submit_build_job(server, job)

print 'Build for job %s submitted...' % job

if monitor_build_job(server, job):
    print 'Job build for %s completed' % trigger_queue['artifact_id']
else:
    print 'Job build for %s failed' % trigger_queue['artifact_id']
Submit build for job communities/Gitlab Groups/ec-better/wfp/triggers/tg-wfp-01-01-02-queue/docker...
Build for job communities/Gitlab Groups/ec-better/wfp/triggers/tg-wfp-01-01-02-queue/docker submitted...
Job build for tg-wfp-01-01-02-queue completed