Giter VIP home page Giter VIP logo

jenkins-spock's Introduction

Jenkins Pipeline Support for Spock

Utility classes to help with testing Jenkins pipeline scripts and functions written in Groovy.

User Guide (GroovyDoc)

Add this library to pom.xml in the test scope:

<dependency>
	<groupId>com.homeaway.devtools.jenkins</groupId>
	<artifactId>jenkins-spock</artifactId>
	<scope>test</scope>
</dependency>

Check the CHANGELOG.md to find the available versions.

Working Examples

The examples directory contains working sample projects that show off the major kinds of project this library can be used with. Check them out and try building them yourself!

Specifications

This library provides a JenkinsPipelineSpecification class that extends the Spock testing framework's Specification class. To test Jenkins pipeline Groovy code, extend JenkinsPipelineSpecification instead of Specification. Please see the GroovyDoc for JenkinsPipelineSpecification for specific usage information and the Spock Framework Documentation for general usage information.

During the tests of a JenkinsPipelineSpecification suite,

  1. All Jenkins pipeline steps (@StepDescriptors) will be globally callable, e.g. you can just write sh( "echo hello" ) anywhere.
    1. "Body" closure blocks passed to any mock pipeline steps will be executed.
  2. All Jenkins pipeline variables (@Symbols and GlobalVariables) will be globally accessible, e.g. you can just write docker.inside(...) anywhere
  3. All Pipeline Shared Library Global Variables (from the /vars directory) will be globally accessible, so you can just use them anywhere.
  4. All interactions with any of those pipeline extension points will be captured by Spock mock objects.
  5. You can load any Groovy script (Jenkinsfile or Shared Library variable) to unit-test it in isolation.
  6. The Jenkins singleton instance will exist as a Spock mock object.
  7. The CpsScript execution will exist as a Spock spy object (you should never need to interact with this, but it's there).

Dependencies

There are some dependencies of this library that are marked with Maven's provided scope. This means that Maven will pull them in for building and testing this library, but when you use this library you must pull those libraries in as dependencies yourself.

This is done because these dependencies - things like the Jenkins Pipeline API, JUnit, etc - are things that

  1. You absolutely have to have as dependencies in your project in order for this library to be of any use
  2. Should not have their version or final scope controlled by this library

The dependencies that should already be in your project in order for using this library to make any sense are:

<dependency>
	<groupId>org.jenkins-ci.main</groupId>
	<artifactId>jenkins-core</artifactId>
	<version>${jenkins.version}</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>org.jenkins-ci.plugins.workflow</groupId>
	<artifactId>workflow-step-api</artifactId>
	<version>${jenkins.workflow.step.version}</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>org.jenkins-ci.plugins.workflow</groupId>
	<artifactId>workflow-cps</artifactId>
	<version>${jenkins.workflow.cps.version}</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>org.jenkins-ci</groupId>
	<artifactId>symbol-annotation</artifactId>
	<version>${jenkins.symbol.version}</version>
	<scope>test</scope>
</dependency>

<dependency>
	<groupId>junit</groupId>
	<artifactId>junit</artifactId>
	<version>${junit.version}</version>
	<scope>test</scope>
</dependency>

<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>javax.servlet-api</artifactId>
	<version>${jenkins.servlet.version}</version>
	<scope>test</scope>
</dependency>

Depending on your parent pom, some of the ${jenkins.version} properties may already be defined. Be sure you define any that are not.

If your code actually writes code against classes in any of these dependencies, remove the <scope>test</scope> entry for the corresponding block(s).

Developer Guide

Building

The build of jenkins-spock is built with Maven. Normal Maven lifecycle phases apply. As long as you have a contemporary (1.8+) JDK and Maven (3.3+), it should build fine.

Releasing

jenkins-spock should be released by the maven-release-plugin:

mvn clean release:prepare release:perform

In order for this to succeed, the user running this must

  1. Configure GitHub credentials with push access to this repository.
  2. Configure Sonatype Nexus credentials with deploy access to the com.homeaway groupId.
  3. Configure a PGP identity so that the maven-gpg-plugin can sign artifacts.

jenkins-spock's People

Contributors

awittha avatar xaseron avatar neoword avatar

Stargazers

Elijah Shackelford avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.