Skip to content

AlexanderZobkov/jenkins-scripting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jenkins scripting

Build Status

This repository contains a Maven project that can help you to ease developing and learning of Jenkins groovy scripts.

This Maven project contains steps to compile groovy scripts and send them for execution to an instance of Jenkins. This allows to automate such manual steps, that you do while developing or learning Jenkins scripts, as copy-pasting from some text editor to Jenkins script console (https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console) and pushing "run" button.

Additionally, if you would like to develop your jenkins groovy scripts or explore Jenkins API (http://javadoc.jenkins-ci.org/) with support of code completion or type inference features, open this Maven project in any modern IDE that supports Maven and Groovy.

Usage

  1. Adjust Jenkins connectivity and credentials settings

    • Directly in the pom.xml

      ...
      <jenkins.url>CHANGE_ME</jenkins.url>
      <jenkins.user>CHANGE_ME</jenkins.user>
      <jenkins.token>CHANGE_ME</jenkins.token>
      ...
    • Or override the properties with CLI options for Maven

      mvn -Djenkins.url=<url> -Djenins.user=<user> -Djenkins.token=<token> ....
  2. Check you are able to execute jenkins scripts

    $ mvn clean test
  3. Add dependencies specific to your jenkins installation to the pom.xml

    // Put the script to http://<jenkins-controller>/manage/script to generate Maven dependencies declarations.
    StringBuilder reply = new StringBuilder()
    Jenkins.instance.pluginManager.plugins.each {
        def attributes = it.getManifest().getMainAttributes()
        reply << "<dependency>\n"
        reply << "  <groupId>${attributes.getValue('Group-Id')}</groupId>\n"
        reply << "  <artifactId>${attributes.getValue('Short-Name')}</artifactId>\n"
        reply << "  <version>${attributes.getValue('Plugin-Version')}</version>\n"
        reply << '</dependency>\n'
    }
    reply.toString()
  4. Code in src/main/groovy/jenkins-script.groovy If Jenkins core API is not enough for your needs, add dependencies for that or this jenkins plugin to the pom file.

  5. Try the script

    $ mvn test
  6. Return to coding

Releases

No releases published

Packages

No packages published