Giter Site home page Giter Site logo

analogj / job-dsl-gradle-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sheehan/job-dsl-gradle-example

0.0 3.0 0.0 189 KB

An example Job DSL project that uses Gradle for building and testing.

License: Apache License 2.0

Groovy 97.76% Shell 2.24%

job-dsl-gradle-example's Introduction

Jenkins Job DSL Gradle Example

An example Job DSL project that uses Gradle for building and testing. Check out this presentation for a walkthrough of this example (starts around 14:00).

File structure

.
├── jobs                    # DSL script files
├── resources               # resources for DSL scripts
├── src
│   ├── main
│   │   ├── groovy          # support classes
│   │   └── resources
│   │       └── idea.gdsl   # IDE support for IDEA
│   └── test
│       └── groovy          # specs
└── build.gradle            # build file

Script Examples

  • Example 1 - shows basic folder/job creation
  • Example 2 - shows how to create a set of jobs for each github branch, each in its own folder
  • Example 3 - shows how to use the configure block
  • Example 4 - shows a way to reuse job definitions for jobs that differ only with a few properties
  • Example 5 - shows how to pull out common components into static methods
  • Example 6 - shows how to include script resources from the workspace
  • Example 7 - shows how to create jobs using builders
  • Example 8 - shows how to use DSL extensions provided by other plugins

Testing

./gradlew test runs the specs.

JobScriptsSpec will loop through all DSL files and make sure they don't throw any exceptions when processed.

Debug XML

./gradlew debugXml -Dpattern=jobs/**/*Jobs.groovy runs the DSL and writes the XML output to files to build/debug-xml.

This can be useful if you want to inspect the generated XML before check-in.

Seed Job

You can create the example seed job via the Rest API Runner (see below) using the pattern jobs/seed.groovy.

Or manually create a job with the same structure:

  • Invoke Gradle script → Use Gradle Wrapper: true
  • Invoke Gradle script → Tasks: clean test
  • Process Job DSLs → DSL Scripts: jobs/**/*Jobs.groovy
  • Process Job DSLs → Additional classpath: src/main/groovy
  • Publish JUnit test result report → Test report XMLs: build/test-results/**/*.xml

REST API Runner

A gradle task is configured that can be used to create/update jobs via the Jenkins REST API, if desired. Normally a seed job is used to keep jobs in sync with the DSL, but this runner might be useful if you'd rather process the DSL outside of the Jenkins environment or if you want to create the seed job from a DSL script.

./gradlew rest -Dpattern=<pattern> -DbaseUrl=<baseUrl> [-Dusername=<username>] [-Dpassword=<password>]

  • pattern - ant-style path pattern of files to include
  • baseUrl - base URL of Jenkins server
  • username - Jenkins username, if secured
  • password - Jenkins password or token, if secured

job-dsl-gradle-example's People

Contributors

daspilker avatar jbyler avatar kmarquardsen avatar knjname avatar lotharschulz avatar sheehan avatar signed avatar tduchateau avatar tobix avatar volkovs avatar

Watchers

 avatar  avatar  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.