Build the triggerΒΆ

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.

In [1]:
import time
import getpass
import jenkins
  • Define the data transformation application information
In [2]:
trigger = dict([('artifact_id', 'tg-satcen-01-02-02'),
                ('repository', 'Gitlab Groups'),
                ('folder', 'satcen'),
                ('community', 'ec-better')])
  • Set the authentication information:
In [3]:
username = raw_input("What is your Jenkins username? ")
api_key = getpass.getpass('And your Jenkins API key:')
  • First the import of the required Python libraries:
  • 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='https://build.terradue.com',
                         username=username,
                         password=api_key)
  • Submit the build request for the two trigger applications:
In [ ]:
for trigger_mode in ['queue', 'pipe']:

    job = 'communities/%s/%s/%s/triggers/%s-%s/docker' % (trigger['repository'],
                                                          trigger['community'],
                                                 trigger['folder'],
                                                 trigger['artifact_id'],
                                                 trigger_mode)

    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-%s completed' % (trigger['artifact_id'], trigger_mode)
    else:
        print 'Job build for %s-%s failed' % (trigger['artifact_id'], trigger_mode)
Submit build for job communities/Gitlab Groups/ec-better/eth-z/triggers/tg-ethz-01-03-01-queue/docker...
Build for job communities/Gitlab Groups/ec-better/eth-z/triggers/tg-ethz-01-03-01-queue/docker submitted...