5. Customizing the Project

Spring Cloud Pipelines offers a number of ways to customize a Pipelines project:

5.1 Overriding Scripts

Since Spring Cloud Pipelines evolves, you may want to pull the most recent changes to your Spring Cloud Pipelines fork. To not have merge conflicts, the best approach to extending the functionality is to use a separate script with customizations.

When we execute a script that represents a step (for example, a script named build_and_upload.sh), after we source all the deployment and build-specific scripts (such as pipeline-cf.sh and projectType/pipeline-jvm.sh with projectType/pipeline-gradle.sh), we set a hook that lets you customize the behavior. If the script that we run is common/src/main/bash/build_and_upload.sh, we search for a script in the Spring Cloud Pipelines repository under common/src/main/bash/custom/build_and_upload.sh, and we source that script just before running any functions.

The following example shows such a customization:

Example 5.1. custom/build_and_upload.sh

#!/bin/bash

function build() {
    echo "I am executing a custom build function"
}

export -f build

when the build function is called for our Gradle project, instead of calling the Gradle build process, we echo the following text: I am executing a custom build function.

5.2 Overriding Pipelines

Currently, the best way to extend the Concourse and Jenkins Jenkinsfile pipelines is to make a copy of the Concourse pipeline yaml files and the Jenkins seed and pipeline jobs.

5.2.1 Overriding Jenkins Job DSL pipelines

We provide an interface (called org.springframework.cloud.pipelines.common.JobCustomizer) that lets you provide customization for:

  • all jobs
  • build jobs
  • test jobs
  • stage jobs
  • prod jobs

We use the JDK’s java.util.ServiceLoader mechanism to achieve extensibility.

You can write an implementation of that interface (for example, com.example.MyJubCustomizer) and create a META-INF/org.springframework.cloud.pipelines.common.JobCustomizer file in which you put the com.example.MyJubCustomizer line.

If you create a JAR with your class (for example com.example:my-customizer:1.0.0), put it on the build classpath, as the following example shows:

dependencies {
    // ...
    libs "com.example:my-customizer:1.0.0"
    // ...
}

If you do not want to create a separate library, you can create an implementation in the sources under src/main/resources/META-INF.

Regardless of what you chose, your implementation runs for each job. You can add notifications or any other customizations of your choosing.

5.3 Picking Features

If you want to pick only pieces (for example you want only Cloud Foundry combined with Concourse), you can run the following command:

$ ./gradlew customize

A screen resembling the following appears:

:customize
  ___          _              ___ _             _   ___ _           _ _
 / __|_ __ _ _(_)_ _  __ _   / __| |___ _  _ __| | | _ (_)_ __  ___| (_)_ _  ___ ___
 \__ \ '_ \ '_| | ' \/ _` | | (__| / _ \ || / _` | |  _/ | '_ \/ -_) | | ' \/ -_|_-<
 |___/ .__/_| |_|_||_\__, |  \___|_\___/\_,_\__,_| |_| |_| .__/\___|_|_|_||_\___/__/
     |_|             |___/                               |_|



Follow the instructions presented in the console or terminate the process to quit (ctrl + c)


=== PAAS TYPE ===
Which PAAS type do you want to use? Options: [CF, K8S, BOTH]
<-------------> 0% EXECUTING
> :customize

Now you need to answer a couple of questions. Depending on your choices, whole files and their pieces get removed and updated accordingly. For example, if you choose the CF and Concourse options, the Kubernetes and Jenkins configuration and folders and pieces of code in the project get removed.