Back to blog

Introducing a New Way to Define Jenkins Pipelines

Andrew Bayer
September 06, 2016
This is a guest post by Jenkins World speaker Andrew Bayer, Jenkins developer at CloudBees.

Jenkins World

Over the last couple years, Pipeline as code has very much become the future of Jenkins - in fact, at this point, I’d say it’s pretty well established as the present of Jenkins. But that doesn’t mean it’s done, let alone that it’s perfect. While many developers enjoy the power and control that they get from writing Pipelines using scripting, not everyone feels the same way. A lot of developers want to specify their build as configuration and get on with building software.

Pipeline scripts haven’t been a good way to do that…​until now.

With new changes to Jenkins Pipeline, you are now able to define your Pipeline from configuration in your Jenkinsfile by installing the new Pipeline Model Definition plugin. It’s available today for you to try via the update center. Be sure to check the documentation for examples on how to get started for a variety of languages and platforms.

Here’s a quick example based on the plugin’s own Jenkinsfile:

pipeline {
    // Make sure that the tools we need are installed and on the path.
    tools {
        maven "Maven 3.3.9"
        jdk "Oracle JDK 8u40"
    }

    // Run on any executor.
    agent label:""

    // The order that sections are specified doesn't matter - this will still be run
    // after the stages, even though it's specified before the stages.
    postBuild {
        // No matter what the build status is, run these steps. There are other conditions
        // available as well, such as "success", "failed", "unstable", and "changed".
        always {
            archive "target/**/*"
            junit 'target/surefire-reports/*.xml'
        }
    }

    stages {
        // While there's only one stage here, you can specify as many stages as you like!
        stage("build") {
            sh 'mvn clean install -Dmaven.test.failure.ignore=true'
        }
    }

}

It’s still early days for this feature, with a lot of further functionality planned to make it easier and more intuitive to define your Pipelines. All of that functionality lives on top of Pipeline scripting, so we’ll also keep improving Pipeline steps and syntax outside of the model! And perhaps most exciting, the Pipeline model will be used by an in-the-works visual editor that will be part of the Blue Ocean project - while the editor isn’t ready yet, the Pipeline Model Definition plugin will be bundled with the Blue Ocean beta for you to try out.

I’ll be going into all of this and more at my talk on Thursday, September 15th, at 3:45pm at Jenkins World, and showing off the same day at the lunchtime demo theater. I can’t wait to see you all there and hear what you think of all this!

Andrew will be presenting more of this concept at Jenkins World in September. Register with the code JWFOSS for 20% off your full conference pass.

About the author

Andrew Bayer

Andrew was a core committer to Hudson and the author of numerous plugins.