This tutorial will illustrate how you can integrate Lenses into your Jenkins CI/CD using the lenses-cli.
The Lenses CLI allows you to manage your Apache Kafka environment using a single unified and secure API across all Kafka components (Kafka Brokers, Zookeepers, Kafka Connect, Schema Registry etc.).
Integrating Lenses with Jenkins will simplify automating the deployment of real time applications across your different Apache Kafka environments.
To demonstrate the integration, we will simply walk you through a very basic example of triggering a job that uses the to list the available topics in your Apache Kafka cluster. See this blog for more details about managing your Apache Kafka flows via GitOps.lenses-cli
Pre-requisites
In order to be able to follow the steps of this blog, you will need the following:
Lenses up and running. You can use our free Box instance if necessary.
A Jenkins server up and running and accessible from the Internet. Additionally, the Jenkins server should have the required plugins for GitHub support installed.
A working network connection between these two machines.
A GitHub repository with administrative privileges on it.
The Scenario
The Jenkins job that will be implemented will download and query a Lenses instance for information using the lenses-cli
account.admin
We are going to use a public GitHub repository in order to avoid having to authenticate to GitHub from Jenkins, which will make the scenario more complex. The URL for the GitHub repository is https://github.com/mactsouk/jenkins-blog – you should use your own GitHub repository or any other repository as long as you can create a Webhook for it.
The Implementation
This section will illustrate the steps needed for implementing the scenario.
Note that both Jenkins and Lenses servers will be exposed to the Internet using the utility, which explains the hostnames of the servers. The Jenkins server hostname is ngrok
whereas the Lenses server hostname is 15789550.ngrok.io
.a00474c0.ngrok.io
GitHub Webhook
In order to get the Webhook, you should go to the home page of your repository and then select the tab. Then, select the Settings
option on the left column and then click on the Webhooks
button. The values that were used for the webhook are shown in the next screenshot:Add Webhook

After we are done, we will press the button or the Add Webhook
if the webhook was already created. Note that you will need to add the Update Webhook
string at the end of the Jenkins hostname – this is really important for the scenario to work./github-webhook/
This step was needed in order for GitHub to inform Jenkins about changes to the GitHub repository.
Creating the Jenkins Job
This is the most critical part of the process as you will need to create a Jenkins job and correctly associate it with the appropriate GitHub repository.
Go to Jenkins UI and click on link. You will presented with the next screen:create new jobs

Enter as the name of the item and select the Lenses
. After that click on the Freestyle project
button at the bottom of the screen.OK
The next string is pretty long so it will be presented in two steps. The first part is about specifying the GitHub project URL and selecting the , which will be Git and filling in the correct information – see the next screenshot for more information:Source Code Management tool

The second part is about selecting the box and defining the job under the GitHub hook trigger for GITScm polling
title. On the Build
menu select the Add Build step
item. After that, insert the desired UNIX commands in the box. The final configuration is presented in the following screenshot.Execute shell

Click on button and you are done with the definition of the job. After that, each time someone makes a push to the associated GitHub repository, the Jenkins job will be triggered.Save
The shell commands that will be executed in the Jenkins job are the following:bash
```
uname -a
wget https://github.com/lensesio/lenses-go/releases/download/3.1.0/lenses-cli-linux-386.tar.gz
tar xzvf lenses-cli-linux-386.tar.gz
mv lenses-cli-linux-386 lenses-cli
./lenses-cli --host http://a00474c0.ngrok.io --pass admin --user admin topics
```
informs us about the characteristics of the UNIX machine and is not necessary to be executed – it just gives you a good idea of the Linux system you will be working on. uname
The command downloads the wget
archive, which is extracted using lenses-cli
and renamed totar
. Last, lenses-cli
connects to the desired Lenses server lenses-cli
), using the specified username and password information and gets a list of the available Kafka topics. This will download the client each time the job runs, you may want to place the client in your Jenkins workspace in order to avoid unnecessary bandwidth use and improve execution time.(http://a00474c0.ngrok.io
You can also authenticate using a service account if you do not want to use a regular account:
```
lenses-cli --host http://a00474c0.ngrok.io --token <service account name>:
<service token> topics
```
This is a simple job but you can perform any job you want. Look at the GitHub Actions + Lenses blog post for learning how to insert data into Kafka through Lenses using shell commands and at lenses-cli documentation.
Pushing data to the GitHub repository
Now all you have to do is perform a push to the GitHub repository and the Jenkins job will be automatically triggered.

Watching the results
Click on the link, or on any other link that exists there, in order to see more information about the execution of the job.#1

Click on the link of the left in order to see the output of the shell commands of the job.Console Output
You will see lots of output related to the execution of the command - if you want less output from wget
, please use the wget
option. The bottom of the screen will look as follows:--quiet

The last output verifies that was successfully downloaded and connected to the desired Lenses server in order to list the available Kafka topics!lenses-cli
Next Steps
Now that you know how to use GitHub actions to communicate with Lenses, you should start automating as many things as possible. Learn how to apply GitOps to your real time pipelines in our blog post.







