A Jenkins YAML pipeline example

Don’t get too excited. Official Jenkins YAML build job support isn’t here yet.

It’s available if you’re a GitHub Actions user. And it’s available if you build with GitLab CI/CD. But Jenkins YAML support isn’t currently part of the official distribution.

Instead, Jenkins users are limited to scripted and declarative pipelines. But if you are one of those early-adopter types, you can dip your Jenkins toes in the YAML waters. Simply install the incubating GitHub YAML Pipeline plugin.

Jenkins YAML support

In a recent Jenkins tutorial posted on TheServerSide, I demonstrated how to perform a two stage pipeline build that pulled code from GitHub and built a Maven based application. Here is the non-YAML version of the CI/CD build script in all its glory:

pipeline {
  agent { docker { image 'cameronmcnz/ant-jdk8-git:latest' } }
  stages {
    stage('Log Jenkins Maven Docker Git and Java version info') {
      steps {
        sh 'mvn -version'
        sh 'java -version'
	sh 'git --version'
      }
    }
    
    stage('GitHub Jenkins Maven Docker Build') {
      steps {
        sh 'mvn clean compile test install'
      }
    }
  }
}

Declarative vs. YAML pipelines in Jenkins

So, how would a Jenkins YAML pipeline compare? They’re actually pretty similar.

Developers will notice that with a Jenkins YAML pipeline, the round and curly brackets go away, resulting in a significantly cleaner and less verbose build file. To compare, here’s what the Jenkins YAML pipeline build file looks like:

Jenkins YAML pipeline

The Jenkins YAML pipeline is still in its incubation period.

pipeline:
  agent:
    any:
  stages:
    - stage: "Log Jenkins Maven Docker Java and Git versions"
      steps:
        - sh "mvn -version"
        - sh "java -version"
        - sh "git --version"
        - sh "docker --version"
    - stage: "Jenkins YAML Maven Build"
      steps:
        - git "https://github.com/learn-devops-fast/rock-paper-scissors.git"
        - sh "mvn clean compile test install"
    - stage: "Final Jenkins YAML Pipeline Stage"
      steps:
        - sh "echo 'Jenkins YAML Pipeline Complete'"

Full Jenkins YAML pipeline support?

The Jenkins YAML plugin is tagged in the marketplace as being in the incubation stage, which means there’s no word on when it will be officially released and packaged as part of the distribution. There’s been talk about Jenkins YAML pipeline support for a few years, but there hasn’t been a strong impetus to push the feature through.

However, as the popularity of YAML-based, GitHub Actions pipelines continues to rise — along with GitLab support for YAML — my guess is the timeline for a fully supported release will come soon.

I predict we will see Jenkins YAML pipelines officially included in a release midway through 2021, although that timeline is pure speculation.

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close