Search code examples
vimjenkinsvim-pluginjenkins-api

Is there a standard way of interacting with Jenkins inside Vim?


At work we have recently started using Jenkins. I would like to be able to see the basic status of builds from within Vim. Is there a typical or standard way of doing this?

Currently i am using my own script which interacts with the jenkins API but it seems unlikely to me that there would be no more common ways of doing something which i think rather a lot of people would want to do.


Solution

  • You can use this vim plugin, which I have developed;

    https://github.com/burnettk/vim-jenkins

    Since most apps that use Jenkins going forward will use Jenkinsfiles, I decided to use that as the hook. So what you do is add a comment anywhere in your Jenkinsfile with the path to its build plan, like this:

    // BUILD_PLAN_PATH: /view/Sweetapps/job/hot-app/job/master
    

    This comment is theoretically useful even apart from this feature as documentation, but its purpose is for the plugin to parse it to figure out how to interact with the jenkins API to fetch the build status (FAILURE/SUCCESS/etc) for the build plan that goes with this Jenkinfile. Once the comment is in place, fetch your build status by running:

    :JenkinsShowLastBuildResult
    

    Or its shortcut ("jenkins build"):

    <Leader>jb
    

    The build status will be echo'ed into your vim window.

    My favorite feature is still Jenkinsfile validation. I use it multiple times a day.

    :JenkinsValidateJenkinsFile
    

    or the shortcut (short for "jenkins Jenkinsfile"):

    <Leader>jj
    

    Hopefully people like the features, and maybe get some ideas about other features that might be useful to add. Pull requests are of course welcome. I intend to add a feature to open the same build plan that is already documented in the Jenkinsfile in a browser window (using mac "open", but probably if anyone cares to make it work on linux or windows, it would be possible).