Configuration as Code (CasC) for Masters

Configuration as Code (CasC) for Masters is available on the following platforms:

  • CloudBees Core on traditional platforms 2.222.4.3 (and higher)

  • CloudBees Core on modern cloud platforms 2.222.4.3 (and higher)

  • CloudBees Jenkins Platform 2.222.4.3 (and higher)

Introducing Configuration as Code (CasC) for Masters

Configuration as Code (CasC) for Masters simplifies the management of a CloudBees Core cluster by capturing the configuration of CloudBees Core masters in human-readable declarative configuration files which can then be applied to a master in a reproducible way. By capturing the configuration in files, it can be treated as a first class revision-controlled artifact - versioned and then applied to masters while being centrally managed from CloudBees Core Operations Center.

Configuration as Code (CasC) for Masters architecture

The process of using Configuration as Code (CasC) for Masters involves the following steps:

  1. Create a configuration bundle

  2. Make configuration bundle available for distribution by Operations Center

  3. Assign a configuration bundle to a master

Understanding configuration bundles

The configuration of a master is described in a collection of YAML files referred to as a Configuration as Code (CasC) for Masters bundle. The Operations Center can store many different configuration bundles representing a selection of predefined masters. Configuration bundles are stored securely on the Operations Center server which manages the secure distribution of the Configuration as Code (CasC) for Masters bundles to the correct masters.

Creating a configuration bundle

To create a new bundle configuration, you must create each of the files listed below. A Configuration as Code (CasC) for Masters bundle consists of the following files:

  • bundle.yaml - This file is an index file that describes the bundle, and references the other files in the bundle.

  • jenkins.yaml - This file contains the Jenkins configuration, as defined by the Configuration as Code plugin.

  • plugins.yaml - This file contains a list of all the plugins that should be installed on the master.

  • plugin-catalog.yaml - This file contains the plugin catalog definitions that should be created on the master.

    For the bundle to be valid, all of the above files must be present with exactly these filenames.

bundle.yaml

The bundle.yaml file is an index file that describes the bundle and references the other files in the bundle. The file must contain all of the properties listed below:

Property Type Description

id

String

This bundle’s unique identifier

version

String

This bundle’s version, this value should be incremented whenever the bundle is modified.

apiVersion

String

This is the bundle’s API version. Currently, the expected value is "1".

description

String

A helpful description of this bundle.

plugins/jcasc/catalog

List of Strings

References to the plugins.yaml, jenkins.yaml, and plugin-catalog.yaml files respectively. These sections must appear exactly as specified in the example.

Sample bundle.yaml file

id: "git-bundle"
version: "1"
apiVersion: "1"
description: "A simple bundle that sets up a master with the git-client plugin"
plugins:
  - "plugins.yaml"
jcasc:
  - "jenkins.yaml"
catalog:
  - "plugin-catalog.yaml"

jenkins.yaml

This file is the main Configuration as Code (CasC) for Masters configuration file that describes the master. For more information on how to format this file, see the documentation of the Jenkins Configuration-as-Code plugin.

Sample jenkins.yaml file

jenkins:
  systemMessage: "Jenkins configured using CasC."
  numExecutors: 0
  mode: NORMAL
  securityRealm:
    local:
      allowsSignup: false
      users:
       - id: admin
         password: Qmas9pHXb9wpvp36FaAQ2SBN7XBxsG3h
       - id: newuser
         password: VzHAzoGzHeoq4JF797p8Mb7qL2Ycv54A

plugins.yaml

This file lists all of the plugins that should be installed on the master. All plugins listed must be in the CloudBees Assurance Program (CAP). Plugins outside of CAP (for example, Open Source or your own plugins) should be added via a Plugin Catalog (see the next section).

The contents of this file should be a list of plugin IDs. Find many popular plugins and their IDs at the following sites:

Sample plugins.yaml file

plugins:
  - id: "git"
  - id: "maven-plugin"

plugin-catalog.yaml

This file defines the catalog of plugins that are available for installation on the master. The plugin catalog contains a list of plugins along with the version that should be installed. An optional location can also be specified for plugins that are not available in the standard update centers. For more information on Plugin Catalogs, see Configuring plugin catalogs.

Plugins will not actually be installed on the master unless they are listed in plugins.yaml. Transitive dependencies are not automatically added. See Calculating plugin dependencies for more information on creating a list of transitive dependencies.
The Plugin Template Catalog feature can be also used separately (non CasC) on CloudBees Core masters as described in the documentation. However when using it inside a CasC bundle there are some limitations. See Plugin Catalog limitations in Configuration as Code (CasC) for Masters for more information.

Sample plugin-catalog.yaml file

type: plugin-catalog
version: '1'
name: java-catalog
displayName: Java Master Catalog
configurations:
- description: java-builder
  includePlugins:
    artifactory:
      version: 3.3.2
    checkstyle:
      version: 4.0.0
    warnings-ng:
      version: 5.3.0
    my-custom-plugin:
      url: http://www.example.org/jenkins-plugins/my-custom-plugin-1.2.3.hpi

Generating Configuration as Code (CasC) for Masters YAML files from pre-existing masters

A blank slate is not ideal when there is a lot to define. It’s easier to configure Jenkins using the UI and then export that configuration as a Configuration Bundle. Configuration as Code (CasC) for Masters includes a method for creating Configuration as Code (CasC) for Masters YAML files from pre-existing masters. However, the generated bundle is not an exact replica of the existing master and needs to be completed manually.

The export feature in Configuration as Code (CasC) for Masters for relies on OSS Configuration as Code export, which has limitations (See JCasC OSS documentation for more information). In other words, the configuration bundle generated by exporting it from an existing master is not offering a complete, correct, and ready-to-use configuration bundle.

One reason the exported bundle is incomplete is that some plugins are only partially compatible with Configuration as Code, which means they can read and load the configuration coming from Configuration as Code (CasC) for Masters; however, they are not generating the correct YAML when exporting. Also, the jenkins.yaml section can include extraneous default values for some properties that can be removed.

When exporting CasC bundles from existing masters, it is recommended that the master has no BeeKeeper warnings related to plugins when doing the export, as the exporting logic relies on the CloudBees Assurance Program to generate consistent plugins.yaml and plugin-catalog.yaml files. The export will still return content when there are BeeKeeper warnings; however, the consistency of plugins.yaml and plugins-catalog.yaml is not guaranteed. In other words, the files might not be usable without modifications because there will be warning comments in those files pointing to the conflicting plugins.

Exporting a Configuration as Code (CasC) for Masters bundle from existing masters involves the following steps:

  1. Create a Test Master in your cluster.

  2. Configure it as you like (plugins and global configuration).

  3. Optionally configure a Plugin Catalog.

  4. Navigate to http://[your_master_url]/core-casc-export.

Prerequisites

To create a Configuration as Code (CasC) for Masters bundle from a preexisting master:
  1. Navigate to http://[your_master_url]/core-casc-export. The response will be a composed YAML file containing all the components of the configuration bundle.

    bundle.yaml
    id: "0-client-master"
    description: "Autogenerated bundle descriptor"
    version: "1"
    apiVersion: "1"
    plugins:
      - "plugins.yaml"
    jcasc:
      - "jenkins.yaml"
    catalog:
      - "plugin-catalog.yaml"
    ---- jenkins.yaml
    jenkins:
      agentProtocols:
      - "Diagnostic-Ping"
      - "JNLP4-connect"
      - "OperationsCenter2"
      - "Ping"
      disableRememberMe: false
      markupFormatter: "plainText"
      mode: NORMAL
      myViewsTabBar: "standard"
      numExecutors: 0
      primaryView:
        all:
          name: "all"
      projectNamingStrategy: "standard"
      quietPeriod: 5
      remotingSecurity:
        enabled: false
      scmCheckoutRetryCount: 0
      slaveAgentPort: 0
      systemMessage: |+
        v3 - Master configured automatically by CasC from CJOC
    
      updateCenter:
        sites:
        - id: "virtual-cap-core-cm"
          url: "https://jenkins-updates.cloudbees.com/update-center/envelope-core-cm/update-center.json"
      views:
      - all:
          name: "all"
      viewsTabBar: "standard"
    security:
      apiToken:
        creationOfLegacyTokenEnabled: false
        tokenGenerationOnCreationEnabled: false
        usageStatisticsEnabled: true
      sSHD:
        port: -1
    unclassified:
      contentFilters:
        enabled: false
      experimentalPlugins:
        enabled: false
      location:
        adminAddress: "address not configured yet <nobody@nowhere>"
        url: "http://127.0.0.1.beesdns.com:8080/"
      mailer:
        charset: "UTF-8"
        useSsl: false
      operationsCenterRootAction:
        connectionDetails: "----- BEGIN CONNECTION DETAILS -----\nH4sIAAAAAAAAAA3KQQ6DIBBA0bvMugNDkeBwG8TRmihtYLpqenfJ3738H+wtV4UEW8jBcWD0PjJO\r\
          \nvBEumQllKsHNJc7REzzgWMdLWM5DquKVu0ob/G3n8JfqJ1nrntHQyJlFpK+1m/K+EhOThf8NZy3p\r\
          \n8XIAAAA=\r\n----- END CONNECTION DETAILS -----\n"
      pollSCM:
        pollingThreadCount: 10
    plugins.yaml
    plugins:
    - id: "trilead-api"
    - id: "configuration-as-code"
    - id: "mapdb-api"
    - id: "junit"
    - id: "cloudbees-folder"
    - id: "display-url-api"
    - id: "cloudbees-uc-data-api"
    - id: "operations-center-client"
    - id: "chucknorris"
    - id: "cloudbees-analytics"
    - id: "command-launcher"
    - id: "metrics"
    - id: "mailer"
    - id: "nectar-rbac"
    - id: "operations-center-context"
    - id: "async-http-client"
    - id: "script-security"
    - id: "cloudbees-folders-plus"
    - id: "variant"
    - id: "blueocean-commons"
    - id: "jaxb"
    - id: "jdk-tool"
    - id: "cloudbees-license"
    - id: "structs"
    - id: "support-core"
    - id: "scm-api"
    - id: "token-macro"
    - id: "nectar-license"
    - id: "operations-center-agent"
    - id: "cloudbees-administrative-monitors"
    - id: "cloudbees-assurance"
    - id: "credentials"
    - id: "workflow-api"
    - id: "jackson2-api"
    - id: "cloudbees-blueocean-default-theme"
    - id: "workflow-step-api"
    - id: "bouncycastle-api"
    - id: "apache-httpcomponents-client-4-api"
    - id: "javadoc"
    - id: "ldap"
    - id: "pam-auth"
    - id: "matrix-auth"
    - id: "windows-slaves"
    - id: "antisamy-markup-formatter"
    - id: "matrix-project"
    - id: "beer"
    plugin-catalog.yaml
    type: "plugin-catalog"
    version: "1"
    name: "must-have-catalog"
    displayName: "Must Have Master Catalog"
    configurations:
    - description: "Important plugins"
      includePlugins:
        beer:
          url: "http://jenkins-updates.cloudbees.com/download/plugins/beer/1.2/beer.hpi"
        chucknorris:
          url: "http://jenkins-updates.cloudbees.com/download/plugins/chucknorris/1.1/chucknorris.hpi"
  2. The page is divided into different sections per Configuration as Code (CasC) for Masters file in the bundle. Copy the sections into separate YAML files named as noted below and put them into a folder:

    • bundle.yaml

    • jenkins.yaml

    • plugins.yaml

    • plugin-catalog.yaml

      For the bundle to be valid, all of the above files must be present with exactly these filenames.

Adding a Configuration as Code (CasC) for Masters bundle to Operations Center

Configuration bundles are made available from the Operations Center to connected masters using HTTP/HTTPS. Configuration bundles are stored on the Operations Center server as a directory containing the bundle files. Multiple Configuration as Code (CasC) for Masters bundles can be deployed to the Operations Center server and are all stored in $JENKINS_HOME/jcasc-bundles-store.

Example directory for multiple Configuration as Code (CasC) for Masters bundles

$JENKINS_HOME/jcasc-bundles-store/
├── bundle-1
│   ├── bundle.yaml
│   ├── jenkins.yaml
│   ├── plugin-catalog.yaml
│   └── plugins.yaml
└── bundle-2
    ├── bundle.yaml
    ├── jenkins.yaml
    ├── plugin-catalog.yaml
    └── plugins.yaml

To deploy a Configuration as Code (CasC) for Masters bundle to the Operations Center, copy the directory containing the bundle files to your $JENKINS_HOME/jcasc-bundles-store directory. Ensure the owner and group of the bundle directory and files match those of other files under $JENKINS_HOME and are sufficient to allow the Jenkins user to read the files.

Loading Configuration as Code (CasC) for Masters bundles from an SCM

Operations Center distributes Configuration as Code (CasC) for Masters bundles to masters from local storage; however, Configuration as Code (CasC) for Masters bundles can also be pulled from an external source control management (SCM) system using a Freestyle job in Operations Center that can be triggered manually or using a webhook.

Prerequisites

Configuration as Code (CasC) for Masters bundles can be in one or more SCM repositories; however, this guide assumes all bundles are in the same Git repository, with the following layout:

mycompany.com/config-bundles.git
- my-master-1
  -- bundle.yaml
  -- jenkins.yaml
  -- plugins.yaml
  -- plugin-catalog.yaml
- my-master-2
  -- bundle.yaml
  …

Creating a job in Operations Center

Operations Center distributes bundles from local storage, so to use files from an external SCM system you must create a Freestyle job to pull those bundles from the SCM to local storage.

To create a job to pull Configuration as Code (CasC) for Masters bundles from an SCM to local storage:

  1. Create a Freestyle job in Operations Center.

    You must use a Freestyle job as Pipeline jobs are not supported in Operations Center.
  2. In the Source Code Management section, select an SCM that is supported by Jenkins and enter the repository location.

  3. In the Build section, add an Execute Shell step with the following script:

    cp -r my-master-1 $JENKINS_HOME/jcasc-bundles-store
    cp -r my-master-2 $JENKINS_HOME/jcasc-bundles-store
    $JENKINS_HOME/ is the default Jenkins home directory in CloudBees Core on modern cloud platforms. Update the script if you are running some other CloudBees Core instance.
  4. Save and trigger a build.

Afterwards, Configuration as Code (CasC) for Masters bundles should be available in local storage and ready to be used by masters following the normal procedure.

Triggering the job automatically using Webhooks

One way to trigger a Freestyle job to pull Configuration as Code (CasC) for Masters bundles from an SCM is through the use of webhooks. If your SCM supports Webhooks, configure a webhook in the SCM to trigger builds on the importing job on push events.

Setting up a webhook through your SCM will ensure a change made in the repository will be automatically available to masters using the Configuration as Code (CasC) for Masters bundle.

Updating a Configuration as Code (CasC) for Masters bundle

A configuration bundle can be updated on the Operations Center and will then be automatically distributed to the masters that were initialized with that bundle.

After the initial configuration on startup, there is a background process in the master which is checking for updates of the configuration bundle on Operations Center. If there is an update, then the update process shows an Administrative Monitor in the master to inform the user about the new available configuration.

A bundle update will only be detected when the version attribute specified in the bundle.yaml file has been updated. If the version attribute is not incremented then connected masters will not get the updates in the bundle.

When a Master finds an update to its configuration bundle, an alert is displayed in the Manage Jenkins area.

Apply the update when the master must be restarted; select an appropriate time to do this and then select Safe Restart to have the master restart and apply the updated configuration bundle.

In some instances, a restart will not be required to apply an update to the the master. See Using hot reload on a configuration bundle for more information.

By default masters will check for updates every twenty minutes, but this can be customized by setting the Java system property com.cloudbees.opscenter.client.casc.ConfigurationUpdaterTask.recurrencePeriod to the desired interval, in minutes. For example, to have a Client Master check for updates every five minutes, use the following startup command:

java -Dcore.casc.config.bundle=$JENKINS_HOME/core-casc-bundle-link.yaml \
 -Dcom.cloudbees.opscenter.client.casc.ConfigurationUpdaterTask.recurrencePeriod=5 \
 -jar jenkins.war
updating bundle

Managing your masters with CasC gives you great power and flexibility. With this power and flexibility come risks for errors that could impact your installation. Please review the information below to help guide you as you evolve your CasC bundle.

Risks when updating the bundle.yaml file

The version attribute of this file needs to be updated (incremented) when something changes in the bundle (in any other file). Other attributes rarely change (they are just pointing to the other files in the bundle).

If the version attribute is not incremented then connected masters will not get the changes in the bundle.

Risks when updating the plugins.yaml file

CloudBees Assurance Program (CAP) Tier 1 plugins can be added to your master by adding the plugins to this file. Deleting plugins from the file will not remove them from the master. To remove plugins from the master, delete them in the UI, and before restarting the master, delete them from the plugins.yaml file or they will be reinstalled.

There are no "delete/uninstall” operations when using CasC in general.
All plugins in this file must be CloudBees Assurance Program (CAP) Tier 1 plugins.
To get the list of CloudBees Tier 1 plugins:
  1. Navigate to https://docs.cloudbees.com/plugins.

  2. Select Browse and choose Verified and Proprietary in the filter panel.

For more information on the CloudBees Assurance Program and how CloudBees classifies plugins see CloudBees plugin support policies.

If you want to add a plugin to your master that is not in CAP as Tier 1, add the plugin to the plugin-catalog.yaml file.

When adding a plugin to the plugin-catalog.yaml file which is not a CloudBees Assurance Program (CAP) Tier 1 plugin, all of its dependencies also need to be included either in the plugin-catalog.yaml file or this file if they are Tier 1 in CAP. If the dependencies are not in either file, then the plugin will not be installed and their absence could potentially cause other issues (ie. configuration from jenkins.yaml not applicable thus a start up error).

Risks when updating the plugin-catalog.yaml file

If you want to add a plugin to your master that is not in CloudBees Assurance Program (CAP) as Tier 1, add the plugin to the this file. You will also need to add the plugin’s dependencies either to this file or the plugins.yaml file if they are in CAP as Tier 1.

The plugins in the this file need to be compatible with the set of CAP Tier 1 plugins in the plugins.yaml file. A validation of the plugin-catalog.yaml file is run at startup time. If this validation fails, the plugins in the`plugin-catalog.yaml` file are not installed and your master will continue with its normal startup. This scenario means plugins are not installed, which might lead to other issues (ie. specific configurations in jenkins.yaml can not be applied).

Risks when updating the jenkins.yaml file

This file is edited to change or add Jenkins configurations. There is a wide variety of possible combinations (depending on the plugins being configured as code). This file is entirely managed by the OSS Jenkins Configuration as Code (JCasC) plugin. In other words, all OSS documentation, reported bugs, community blogs, Gitter chats, etc. apply to this file.

The bulk of the content in this file is defined by the various plugins you have installed with only a small portion of it defined by the Jenkins core itself. However, there are a few general items to consider when editing the file:

  • Removing configurations from this file does not remove the configuration from an existing master.

  • Adding configurations requires the underlying plugin that the configuration references to be installed. Jenkins startup will fail otherwise.

  • Backward compatibility depends on the specific plugins being configured. If a plugin changes its configuration in an incompatible way, then the master will fail to start (until the jenkins.yaml file is adapted, or the section in that file related to the plugin removed).

  • This file may contain data which is tied to a specific CloudBees instance (ie. encoded secrets, Operations Center connection details, etc.), so a jenkins.yaml is, in general, suitable for a single CloudBees master instance. This might lead to indecipherable secrets, master to Operations Center connection failing, and many more things depending on the specific configuration.

Using hot reload on a configuration bundle

Configuration as Code (CasC) for Masters allows users to reload a configuration file without restarting the instance. Since the Configuration as Code (CasC) for Masters plugin manages plugin updates and the Plugin Catalog, validating a hot reload is a more complex process. A bundle reload is not always possible. If there are plugin upgrades in the incoming bundle, then Jenkins needs to be restarted.

If the reload is possible, then the following operations are automatically performed:

  • Update the Plugin Catalog

  • Install any new plugins

  • Call the API on configuration-as-code to reload the Jenkins configuration

Configuration bundles that do not include plugin update requirements can be reloaded without an instance restart. This feature allows users to update Jenkins configurations, install new Plugin Catalogs, or install new plugins dynamically.

Setting up a Client Master

Masters send requests for their bundles through a secure HTTP(S) endpoint in Operations Center. Each master is aware of which bundle it is connected to through the bundle-link.yaml file that contains the URL of the bundle to use and the access token.

A Client Master is configured using Configuration as Code (CasC) for Masters by providing it with the location of the appropriate bundle and the access token required to grant access. These are provided in a bundle link file. The Client Master fetches its configuration bundle using the details in the bundle link file and configures itself accordingly.

client master casc

The process of setting up a Client Master involves the following steps:

The connection details needed in the bundle link file, the location of the bundle, and the access token required to grant access, are available in Operations Center. To create the bundle link file, download the bundle link file from Operations Center and save it in the master’s $JENKINS_HOME directory.

To download the bundle link file:
  • From the Operations Center, navigate to Manage Jenkins > Configuration as Code for Masters.

  • Find the configuration bundle in the list.

  • Select Download link file for the configuration bundle.

  • Save the file in the master’s $JENKINS_HOME directory.

The bundle link file contains the following properties:

Property Type Description

url

String

The URL where the bundle can be fetched. This URL references both the Operations Center server and the id of the bundle.

token

String

The access token to authenticate the request with the Operations Center server.

The URL to access a particular bundle from an Operations Center server has a well-defined format: \http[s]://<oc-server>:<port>/config-bundle/<bundle directory> For example, given an Operations Center server on host oc1.example.org and port 8080 the bundle that was placed in directory bundle-1 would be accessed as: http://oc1.example.org:8080/config-bundle/bundle-1 (or https://oc1.example.org:8080/config-bundle/bundle-1).

The Client Master is directed to use the bundle link file by setting a Java system property. On startup, the Client Master will read the bundle link file, fetch its Configuration as Code (CasC) for Masters bundle from the Operations Center using the details specified in the bundle link file, then initialize itself with the provided configuration.

To point the Client Master at the bundle link file, set the Java system property core.casc.config.bundle to the location of the link file. For example, to start a Client Master using the link file at $JENKINS_HOME/jcasc-link.yaml use the following command: java -Dcore.casc.config.bundle =$JENKINS_HOME/jcasc-link.yaml -jar jenkins.war

If there are any errors processing the bundle link file, fetching the bundle from the Operations Center, or initializing based on the bundle, these will be displayed on the console.

Viewing bundles list

All available bundles are listed under Manage Jenkins → Configuration as Code (CasC) for Masters.

For each bundle the following attributes are displayed:

  • Bundle Name: The bundle name (also used as ID). It matches the name of the directory containing the bundle in the filesystem.

  • URL: The bundle URL where Operations Center exposes its content.

  • Master Path: The full path to the master using the bundle (for more information see Linking a bundle to a master)

  • Token: The access token for the bundle.

  • Actions: The three actions available for each bundle, including:

    • Re-generate the access token.

    • Copy the bundle link YAML file content to the clipboard.

    • Download the bundle link YAML file.

Linking a bundle to a master

The Master Path attribute of a bundle indicates to what master the bundle will be applied. This value must be the full path of the master item in Operations Center and it needs to be set before the master is provisioned. If it’s set after the master is provisioned then a re-provisioning is needed for the configuration to take effect.

This parameter is not strictly needed for Client Masters. Client Masters only need to be connected with the correct link file using the download button in the bundles list. However it’s recommended to properly complete this property even for Client Masters for clarity and also for potential features in the future. A bundle is meant to be used in a single master, reusing the same bundle for multiple masters is not recommended.

Re-generating a bundle token

This action re-generates the access token for a bundle. Regenerating the access token is not usually required and should only be done in certain situations. If there is a master using the regenerated bundle, it will lose access to it.

If the token needs to be re-generated (for example, for security reasons) then the master using the token needs to be:

  • Restarted from Operations Center (if it is a Managed Master)

  • Properly reconfigured (if it is a Client Master). The bundle link file needs to be updated with the new token.

As described in other sections, the bundle link file is a YAML formatted file containing the URL and the token to access the bundle in Operations Center. This action copies the content of that file to the clipboard.

This action is rarely required for Managed Masters as the bundle link file is fully managed by the platform.

This action downloads the bundle link YAML file.

This action is rarely used for Managed Masters as the bundle link file is fully managed by the platform, there is no user required action.

Determining plugin compatibility

While there is ongoing work to make Tier 2 plugins compatible with Configuration as Code, not all Tier 2 plugins are compatible at this time.

To determine if a plugin is compatible with CasC:

  1. In a test master, install the plugin.

  2. Configure the plugin in the UI.

  3. Export the CasC bundle.

If the exported bundle contains the plugin’s configuration (as part of the jenkins.yaml file), the plugin is compatible.

Determining if a plugin is Tier 2

To determine if a plugin is a CloudBees Assurance Program (CAP) Tier 2 plugin:
  1. Navigate to https://docs.cloudbees.com/plugins.

  2. Select Browse and choose Compatible in the filter panel.

  3. If your plugin is included in the list, then it is a CAP Tier 2 plugin.

For more information on the CloudBees Assurance Program and how CloudBees classifies plugins see CloudBees plugin support policies.

Plugin Catalog limitations in Configuration as Code (CasC) for Masters

Plugin Catalogs can be used in Configuration as Code (CasC) for Masters bundles through the plugin-catalog.yaml file inside the bundle.

The Plugin Catalog feature can be also used separately (non CasC) on CloudBees Core masters as described in the documentation. However when using it inside a Configuration as Code (CasC) for Masters bundle there are the following limitations:

  • Credentials: The use of Jenkins credentials (under the httpCredentialsProvider section) requires a running Jenkins instance; however, Configuration as Code (CasC) for Masters is designed to run during Jenkins start up, so Jenkins credentials are not available.

  • Maven 2 layout: This layout is not supported when using Plugin Catalogs in a Configuration as Code (CasC) for Masters bundle.

Advanced topics

Enabling HTTPS

The security token and Configuration as Code (CasC) for Masters bundle both contain sensitive information, so it is recommended that they are protected by using HTTPS when sent between the Operations Center and master. HTTPS must be enabled on the Operations Center side. Typically enabling HTTPS is done by terminating the secure connection externally in a reverse proxy, but it can also be terminated in the Jenkins server. To enable HTTPS, add startup parameters to specify the HTTPS port, server certificate, and key.

Example startup parameters

java -jar jenkins.war --httpsPort=8443 \
--httpsCertificate=/etc/certs/jenkins-cert.cert \
--httpsPrivateKey=/etc/certs/jenkins-cert.key

Using a self-signed certificate

This configuration is not recommended and should not be used in production.

If you are using this method in a limited scope for test deployments, see “Set-up SSL on a CJP environment with a self-sign SSL certificate on each Jenkins box”, a CloudBees knowledgebase article, for guidance on setting up CloudBees Core with self-signed certificates.

Calculating plugin dependencies

The Plugin Installation Manager Tool can be used to assist with determining the full list of a plugin’s transitive dependencies. The tool takes as input a plugins.yaml that lists plugins you would like to install and outputs a list of all the plugins to be installed, along with all their transitive dependencies. This list can then be used to populate the plugin catalog so the plugins specified in plugins.yaml can be successfully installed.

The plugins.yaml file used by the tool is not the same as the one created previously when authoring the Configuration as Code (CasC) for Masters bundle.

Prerequisites

  • The plugin.yaml file from the Configuration as Code (CasC) for Masters bundle

  • Java Developer Kit (JDK) installed and configured

  • Apache Maven installed and configured

  • (optionally) git installed and configured

  • Access to the jenkins.war file that will be used to create the connected Master

To create a list of plugins to be installed including all transitive dependencies:

  1. Clone (or download) the Plugin Installation Manager Tool’s repository from https://github.com/jenkinsci/plugin-installation-manager-tool.

  2. Build the tool using the following commands:

    cd plugin-installation-manager-tool
    mvn clean package
  3. Using the plugins.yaml file from the Configuration as Code (CasC) for Masters bundle, create a plugins.yaml file for use with the tool. Rename the Configuration as Code (CasC) for Masters bundle’s plugins.yaml file’s YAML property id to artifactId as illustrated below:

    plugins.yaml from Configuration as Code (CasC) for Masters bundle plugins.yaml for use with tool
    plugins:
      - id: "git"
      - id: "maven-plugin"
    plugins:
      - artifactId: "git"
      - artifactId: "maven-plugin"
  4. Run the tool, using the following command, updating it with the location of your master .war file and the location of your plugins.yaml file:

    cd plugin-installation-manager-tool
    java -jar \
    plugin-management-cli/target/jenkins-plugin-manager-*.jar \
    --no-download --plugin-download-directory plugin-download \
    --list \
    --war $JENKINS_HOME/cloudbees-core-cm.war \  // (1)
    --plugin-file plugins.yaml // (2)
    1 location of master .war file
    2 location of plugins.yaml file

Sample output file with list of plugins

File containing list of plugins to be downloaded: plugins.yaml
Reading in plugins from plugins.yaml

Plugin download location: plugin-download
No CLI option or environment variable set for update center, using default of https://updates.jenkins.io
No CLI option or environment variable set for experimental update center, using default of https://updates.jenkins.io/experimental
No CLI option or environment variable set for incrementals mirror, using default of https://repo.jenkins-ci.org/incrementals
Will use war file: $JENKINS_HOME/jenkins.war

Installed plugins:

Bundled plugins:

Set of all requested plugins:
chucknorris 1.2
workflow-step-api 1.14

Set of all requested plugins that will be downloaded:
chucknorris 1.2
workflow-step-api 1.14

Set of all existing plugins and plugins that will be downloaded:
chucknorris 1.2
workflow-step-api 1.14
Done

Find the section in your output titled Set of all requested plugins that will be downloaded. This section is the list of plugins that will need to be added to plugin-catalog.yaml to successfully install the plugins.yaml.

You may get significantly more output than the example, especially in the “Bundled Plugins” and “Set of all existing plugins and plugins that will be downloaded” sections.

Troubleshooting

Delaying Configuration as Code (CasC) for Masters configuration for Jenkins to load global configuration

Jenkins 2.199 introduced a check to prevent saving global configurations before they are loaded. Configuration as Code (CasC) for Masters needs to apply global configurations before Jenkins loads jobs to correctly reference any global state. Therefore, until JENKINS-51856 is implemented, there is a race condition where Jenkins may fail to start when used with the Configuration as Code plugin.

If you encounter the race condition, Jenkins will fail to start with an exception message similar to the following:

SEVERE	jenkins.InitReactorRunner$1#onTaskFailed: Failed ConfigurationAsCode.init
java.lang.IllegalStateException: An attempt to save the global configuration was made before it was loaded

The workaround for this race condition is to delay Configuration as Code (CasC) for Masters configuration to give Jenkins time to load the global configuration.

To enable this delay, set the io.jenkins.plugins.casc.ConfigurationAsCode.initialDelay system property to the amount of delay time in milliseconds. This delay time value will be dependent on aspects of your system (cpu/disk) and configuration.

To find a value that will work with your system, start with 5000 (5 seconds) and increment by 2000 (2 seconds) until the issue is corrected, then add 1000 (1 second) to the final value for extra safety.

Enabling Configuration as Code (CasC) for Masters configuration delay on a Client Master

Applying the workaround system property to a Client Master depends on the Client Master installation method.

Using the same way other system properties have been added to the init script:

In the same way other system properties have been added to the init script, set the -Dio.jenkins.plugins.casc.ConfigurationAsCode.initialDelay system property to the amount of delay time in milliseconds.

Enabling Configuration as Code (CasC) for Masters configuration delay on a Managed / Team Master

In the case of a Managed or Team Master, the workaround can be applied as a system property on the configuration page of the Master item in the Operations Center dashboard as illustrated below:

Managed Masters configuration page

Validating the bundle deployment in Operations Center

You can check that the configuration bundle is properly deployed to the Operations Center server using an HTTP client tool such as cURL. Use the tool to fetch the bundle.yaml using the URL you entered into the bundle link file. To authenticate the request, you will also need to provide the token value from the bundle link file as an HTTP header named X-CasC-Token.

Example request with authentication token

curl -v -H "X-CasC-Token: abc123def456" \
http://oc1.example.org:8180/config-bundle/bundle-1

This request should return the bundle.yaml file from the configuration bundle in the directory named bundle-1.

If the bundle.yaml file is not returned and you received the following error: No response/connection refused/timeout.

  • Check that the Operations Center server is running.

  • Check that the hostname matches the Operation Center’s.

  • Check that the port in the URL matches the Operations Center’s port.

  • Check whether a firewall between the client and the Operation’s Center could be blocking the connection.

If the bundle.yaml file is not returned and you received the following error: Wrong bundle returned. Check that the bundle files were placed into the correct directory on the Operations Center server.

If the bundle.yaml file is not returned and you received the following error: HTTP status code 404/Not Found returned.

This can happen when either the URL path was incorrect, or the token was not found.

  • Check that the URL matches the format specified above, and that the final part matches the name of the directory containing the configuration bundle.

  • Check that the token value provided matches the one for this bundle in the bundles list in Operations Center (under Manage Jenkins → Configuration as Code for Masters).