Make things a little more beautiful
In the previous post we got a report for our tests:
Nothing wrong about it, but let show the results in a more beautiful way, using the Pipeline Plugin:
Go to Jenkins > Manage Jenkins > Manage Plugins > Add the plugin Build Pipeline Plugin.
Now, with the plugin installed, add a New View > Build Pipeline View:

At this point we have our pipeline configured to run our tests against the API. But, how can I run automatically the tests, every time some new code is pushed into my repository? Let's learn how to do this.
Add Git Support
To add support for git, go to Jenkins > Manage Jenkins > Manage Plugins > Add the plugin Git Plugin.
With this plugin installed, go to Jenkins > Customers API job > Configure > in the section Source Code Management, select the Git option:
Here, you can add your repository in GitHub.

Webhooks?
Remember that, even when you push in GitHub, there is no way your container knows that some code was pushed. We can solve this using webhooks in GitHub, a way that allows us to configure some repository to trigger an event, each time the code is pushed.
Go to you repository in GitHub > Settings > Webhooks > Add Webhook:
You should add a Payload URL, corresponding to the address of you Jenkins container running. Now we have a problem, because how Github can communicate with a local container that it's running in you local machine?
ngrok
Ngrok is a multiplatform tunnelling, reverse proxy software that establishes secure tunnels from a public endpoint such as internet to a locally running network service while capturing all traffic for detailed inspection and replay. Basically we will expose an address that will be achievable by Github and our local container. The use is pretty simple.
- Go to http://ngrok.com and create and account;
- Extract the ngrok package in your machine;
- Each account will create an authorization token. You can see here;
- Go to the directory you added ngrok, and run the command: ./ngrok http 8080
ngrok provides a way to verify this POST locally, so you can ensure everything occurred all right:
With these latest configurations, every time you push some code in your remote branch, a new job will be executed, generating the results in a beautiful pipeline :-)
---------------------------------------------------------------------------------
The source code is available here.
I hope you have enjoyed this small adventure and thank you for your time. Have an awesome day ;-)
No comments:
Post a Comment