1. Home
  2. Integration
  3. Enov8 REST API
  4. Integrating with a CICD Tool
  1. Home
  2. Integration
  3. Popular Integrations
  4. Integrating with a CICD Tool
  1. Home
  2. Integration
  3. Visual Orchestrate
  4. Integrating with a CICD Tool

Integrating with a CICD Tool

In EcoSystem you may want to integrate with your CICD tools.

For example: A build, deployment or test tool.

Here are two examples using one of the favorites, Jenkins.

  1. Get Real-Time information from Jenkins.

Achieved through receiving information via the Rest API.

  1. Tell Jenkins to start a Job

Achieved by calling a VO wrapper script.

Note: All CICD tools would fundamentally work in the same way.

#1 CICD Integrate using EcoSystem Rest-API

Send Information from your CICD Tool

Having a Build Tool (for example Jenkins) update you about Build Success or Versions, can be an invaluable way to track information. Here is a simple exert of Enov8 API code that can be entered your build script and return insights.

Pseudo Code

# Run Build Job as your normally do

# Get latest Job Execution Result from Jenkins (e.g. Jenkins Build Version)

# Build API Payload i.e.

Enov8 System Name + Enov8 Build Tag* Name = Jenkins Build Version

# Send API Payload to your Enov8URL (e.g. by CURL)

Tip*: Tags are a great way to capture general information inside ecosystem, however you could also update other properties, for example CI (Configuration Item) Status.

Real Code Snippet

Example: Jenkins Job sending a build number back to EcoSystem


#Author - Enov8

#Description - This script will update build version from Jenkins to ecosystem

#This will provide the Build Number of the Jenkins job

$JOB_BUILD_NO= $env:BUILD_NUMBER

$ecoAPIURL="ECOSYSTEM API URL" #Ecosystem API Url For Ex http://demo.enov8.com/ecosystem/api

$user_id="ECOSYSTEM USER ID" #Ecosystem User ID

$app_id="ECOSYSTEM API ID" #API User ID

$app_key="ECOSYSTEM API KEY" #API API Key

#global variables below need to be present in config file

$authParams ="user_id="+$user_id+"&"+"app_id="+$app_id+"&"+"app_key="+$app_key #this needs to be added to the EcoAPI in the target environment

$SystemName='GDW' #System Name to Update Version

$eocAPI ='System?'

$postParams = @{

'Resource Name'="$SystemName"

'Version'="$JOB_BUILD_NO"

}

$json = $postParams | ConvertTo-Json

$reqURL = $ecoAPIURL+$eocAPI+$authParams

$postParams | Out-Default

$reqURL | Out-Default

$jsonResp = Invoke-RestMethod -Uri $reqURL -Method Put -Body $json -ContentType 'application/json'

return $jsonResp.result.Get(0).'System ID'

#2 CICD Integrate using Visual Orchestrate

Orchestrate a CICD Tool to do a Task

Orchestration of CICD tools (like Jenkins) is best achieved through the Enov8 Scripting Hub called Visual Orchestrate (VO). VO allows you to add scripts/codes to its Hub & these scripts have unique Target URLs that allow them to be “referenced & invoked” by the CIs or Runsheets.

Quick VO Recap:

  1. The VO hub has a tree structure with scripts (the automation) in the end-nodes.
  2. VO is task agnostic i.e. the script could be for any operational function e.g. build, deploy, test etc.
  3. The VO script can be standalone or simply be an integration wrapper (calling another tool).
  4. VO is language agnostic i.e. it can be in any language e.g. Bash, Java, Perl, Python etc.
  5. Each script has a unique URL for ease of reference/invocation.
  6. You can attach these Target URLs to your Enov8 Runsheets & CIs (Configuration Items).
  7. VO also has its own scheduler for automation that needs run regularly e.g. a shakedown.

Important: The VO scripting hub is limited to premium users only. You could achieve similar affects (assuming moderate coding nous) by employing an Enov8 Webhook. Webhooks sends your listener information when an “Object Changes” (i.e. there is an event e.g. Create, Update & Delete).

Real Code Snippet

Example: VO calling a Jenkins Job


<?php

/*

This VO script (written in PHP) will kickoff Jenkins Build Job

Steps

===========================================================
<ol>
 	<li>Generate CSRF protection token using basic authentication</li>
 	<li>Kickoff the Build Job using the token</li>
</ol>
===========================================================

*/

/*Jenkin Details*/

$JenkinsUsername="User"; // Jenkins Username

$JenkinsPassword="Password"; //Jenkins Password

$JenkinURL="http://JenkinURL";

$JenkinJobName="JenkinJob";

//Generate Token

$BasicAuthenticationToken=base64_encode("$JenkinsUsername:$JenkinsPassword");

$curl = curl_init();

curl_setopt_array($curl, array(

CURLOPT_PORT => "8080",

CURLOPT_URL => $JenkinURL."/crumbIssuer/api/json",

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => "",

CURLOPT_MAXREDIRS => 10,

CURLOPT_TIMEOUT => 30,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => "GET",

CURLOPT_HTTPHEADER => array(

"authorization: Basic $BasicAuthenticationToken"

),

));

$response = curl_exec($curl);

$response = json_decode($response,true);

$crumb=$response['crumb'];

$crumbRequestField = $response['crumbRequestField'];

$Token =$crumbRequestField.":".$crumb;

curl_close($curl);

//Call Jenkins to Kickoff Build Job

$curl = curl_init();

curl_setopt_array($curl, array(

CURLOPT_PORT => "8080",

CURLOPT_URL => $JenkinURL."/job/".$JenkinJobName."/build?token=TEST",

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => "",

CURLOPT_MAXREDIRS => 10,

CURLOPT_TIMEOUT => 30,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => "POST",

CURLOPT_HTTPHEADER => array(

"authorization: Basic $BasicAuthenticationToken",

"cache-control: no-cache",

$Token

),

));

$response = curl_exec($curl);

Updated on March 10, 2019

Was this article helpful?

Related Articles