Thursday, August 17, 2017

How to get plain text inside any XML tag using python

While coding in python, if you need to get plaintext inside a particular tag in XML, you can make use of text iterator provided by ElementTree. You can call itertext() on any XML element, and it returns an iterator which will walk you through text of each tag inside your current element.

The code is simple and self explanatory. You iterate over the text iterator, concatinating text of each element inside given element to some string variable. At the end of the loop, you return the combined text. 

Sunday, August 13, 2017

Developing Jenkins plugin

This blog post is to help you with resources to get you started with Jenkins plugin development. This is NOT a plugin development tutorial. I do not wish to repeat any of the contents which are already available online. This blog post should be seen as a pointer towards those various contents which could help you develop your first Jenkins plugin. 

General idea

As part of my integrations development duties, I needed to work on Jenkins plugin development. The idea was simple: the plugin should work as post-build step, and pull some report from a cloud based system. This plugin is supposed to be used in CD/CI pipeline.

What you need to know to develop Jenkins plugin?

  1. Maven.
  2. Setting up your development environment.
  3. Plugin project structure.
  4. Java.
  5. Groovy script.
  6. Extension points to use in your plugin.
Since I had no prior experience with developing any plugin with Jenkins, I had to start right from the scratch. First obvious step was to start reading and trying out some code. This Jekins wiki page is really helpful getting started. It shows how to setup your development environment, how to test run your code, how to debug, and how to package your plugin.

Its better if you already know how to use Maven, but that is not any hard and fast requirement. Even if you haven't used it earlier, you can still work with that. With help of Maven archetype, you would be generating your starter code. Instructions for that are also given in that Jenkins wiki page. It generates a simple Builder step. 

Point # 6 above is Extension points. There are several classes exposed by Jenkins - called as extension points - which you will be extending or implementing to provide your plugin functionality. For example, to do something after build is completed, you need to extend Notifier class. Whichever class you annotate with @Extension annotation, Jenkins will load at appropriate time - depending on which class you are extending or implementing. 

If you are going to support only freestyle project, you would mostly need to implement SimpleBuildStep class.

Supporting pipelines

As mentioned on Jenkins pipeline page, its a suite you use for continuous integration/delivery. If you need to support pipeline project, SimpleBuildStep may not be the correct choice for you. AFAIK, you need to implement AbstractStepImpl to provide same functionality as a pipeline step. However, this class is marked deprecated and anytime down the line it could be discontinued.

Having said that, I did not find any other alternative to use for pipeline which is as simple as SimpleBuildStep. But, this blog post was very helpful in refactoring the SimpleBuildStep-based code to support pipeline.

Tuesday, June 27, 2017

Somebody found webmon useful!

It gives me great pleasure to let you all know that, somebody have found my Webmon useful! Yes, and they have forked it on github and are using it in their project - of course, with due attribution.

I used it to monitor job portals and career pages of companies of my interest. I maintained it until Feb 2014. After that, it became a dormant project. 

One fine day, I was revisiting my github profile - which I do every week, as such - and found that somebody had forked out my webmon. I quickly opened their repository in other tab and started going through it. As a developer, it was so joyful for me, that my pet work is actually of help to somebody. It just made my entire day! 

So, what is Webmon?

Webmon is a free software, written in PHP. I created it way back in 2013, with following objectives: 
  1. Detect whether listed webpage have any change in contents.
  2. If change is detected, calculate the difference, and output what have changed.
  3. Detect both - positive and negative changes.
I distributed it in the hope that it will be useful, but without any warrenty; without even the implied warranty of merchantability or fitness for a particular purpose. Its still available to everyone. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

I do not have any plan as of now to actively contribute to it and take it further, but I would really like if some other developer starts contributing to it, and make it a truly open source project.