Configuration as Code (CasC) for Masters

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

  • CloudBees CI on traditional platforms 2.222.4.3 (and higher)

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

  • CloudBees Jenkins Platform 2.222.4.3 (and higher)

Introducing CasC

Configuration as Code (CasC) for Masters simplifies the management of a CloudBees CI cluster by capturing the configuration of CloudBees CI 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 CI 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, 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 have exactly these filenames.
You can have a configuration bundle without the plugin-catalog.yaml and plugins.yaml files. If you do not include these files in your bundle, they should not be listed in your bundle.yaml file.

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 CI 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' (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
1 version (required) - must currently have the value 1, which defines the current metadata format for the plugin catalog.

Exporting a CasC bundle

Configuration as Code (CasC) for Masters includes a method for exporting Configuration as Code (CasC) for Masters YAML files from pre-existing masters. This method is helpful for creating example files that can then be used to create a new master that can be connected to Operations Center with Configuration as Code (CasC) for Masters. However, the generated bundle should not be used as is and must be updated manually.

The export feature in Configuration as Code (CasC) for Masters 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 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.

Prerequisites

To Export a Configuration as Code (CasC) for Masters bundle from an existing master:

  1. Create a test master in your cluster using the UI.

  2. Configure it (plugins and global configuration) using the UI.

  3. (Optional) Configure a Plugin Catalog using the UI.

  4. From the master, navigate to Manage Jenkins > Export CloudBees Configuration as Code bundle.

    Export CloudBees Configuration as Code bundle icon
  5. Export the files by selecting the export icon next to each file listed.

    Export CloudBees Configuration as Code bundle
    Figure 1. Export CloudBees Configuration as Code bundle
    You can have a configuration bundle without the plugin-catalog.yaml and plugins.yaml files. If you do not include these files in your bundle, they should not be listed in your bundle.yaml file.
    If the master has CloudBees Assurance Program (CAP)/Beekeeper disabled, the files plugins.yaml and plugin-catalog.yaml are included in the list of files, but they contain one of the following warning messages instead of the expected content:
    • plugin-catalog.yaml message: Cannot export catalog because CAP is not enabled

    • plugins.yaml message: Cannot export plugins because CAP is not enabled

  6. Save the files using the following file names:

    • bundle.yaml

    • jenkins.yaml

    • plugins.yaml

    • plugin-catalog.yaml

      For the bundle to be valid, all of the above files must use these exact filenames.
  7. After creating a configuration bundle based on the export files, add the bundle as a new master and connect it to Operations Center using a casc-bundle-link.yaml file. See [Setting up a Client Master] for more information.

You must remove the obsolete connection details, operationsCenterRootAction, from the jenkins.yaml file before connecting it to the Operations Center so new connection details can be established for this new master. Connection details are specific for a master, and cannot be shared between masters. If you release a Client Master the connection details also change. Do not include them unless you really know what you are doing. If operationsCenterRootAction is not present the in the jenkins.yaml file, Operations Center will create it in the background.

The original test master created in the UI can be deleted as it is no longer needed.

Example exported bundle files

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
  systemMessage: |+
    v3 - Master configured automatically by CasC from Operations Center

  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: "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"

Adding a CasC 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 CasC 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

Manipulating CasC bundles using kubectl

Configuration bundles are stored on the Operations Center in the same way as on traditional platforms, but some additional steps are required to manipulate the files. The following sections explain how to manipulate the bundles using kubectl, the Kubernetes command-line tool. The following sample text will be used where you need to substitute your own values:

  • <NAMESPACE> - the Kubernetes namespace into which you installed CloudBees CI on modern cloud platforms

  • <BUNDLE_DIR> - the local directory containing your bundle files

Users loading bundles from an SCM do not need to use kubectl to manage bundles. For more information, see [Loading Configuration as Code (CasC) for Masters bundles from an SCM].

Listing the bundles currently deployed to the Operations Center

Run the following command to display a list of the bundles that are currently deployed to the Operations Center and available for use:

kubectl exec --namespace <NAMESPACE> cjoc-0 -- \
ls $JENKINS_HOME/jcasc-bundles-store/ | grep -v core-casc-security.xml

Example command to list the bundles deployed to the Operations Center running in namespace cloudbees-core:

kubectl exec --namespace cloudbees-core cjoc-0 -- \
ls $JENKINS_HOME/jcasc-bundles-store/ | grep -v core-casc-security.xml

Example output:

bundle1
bundle2
bundle3

Deploying a bundle to the Operations Center

Copy the directory containing the bundle files to the Operations Center using the following command:

kubectl cp --namespace <NAMESPACE> <BUNDLE_DIR> \
cjoc-0:$JENKINS_HOME/jcasc-bundles-store/

Example command to deploy the bundle directory ‘my-new-bundle’ to the Operations Center running in namespace cloudbees-core:

kubectl cp --namespace cloudbees-core my-new-bundle \
cjoc-0:$JENKINS_HOME/jcasc-bundles-store/

Removing a bundle from the Operations Center

Delete the bundle directory on the Operations Center using the following command:

kubectl exec --namespace <NAMESPACE> cjoc-0 -- \
rm -rf $JENKINS_HOME/jcasc-bundles-store/<BUNDLE_DIR>

Example command to delete the bundle named ‘my-old-bundle’ from the Operations Center running in namespace cloudbees-core:

kubectl exec --namespace cloudbees-core cjoc-0 -- \
rm -rf $JENKINS_HOME/jcasc-bundles-store/my-old-bundle

Updating a bundle on the Operations Center

To update a bundle on the Operations Center, overwrite the bundle files with the updated bundle files and ensure that the version attribute specified in the bundle.yaml file has been updated.

Do not remove the bundle directory on the Operations Center when updating a bundle as that will trigger the Operations Center to re-generate the bundle access token requiring the master using the token to be restarted in order to retrieve the updated bundle from the Operations Center.

Loading CasC bundles from a SCM tool

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 CI. Update the script if your Jenkins home directory is in a different location.
  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 CasC 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.

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

When using CloudBees CI on modern cloud platforms, it is not necessary to create the bundle link file and add the startup options for the Managed Master; these steps are taken care of automatically. However, the Master Path attribute of a bundle, which indicates what master the bundle will be connected to, must be set. The Master Path attribute is the full path of the master item in Operations Center and it must set before the master is provisioned. If it’s set after the master is provisioned, then a re-provisioning is required for the configuration to take effect. See Linking a bundle to a master for more information.

managed master casc

Setting up a Team Master

Configuration bundles can be applied to Team Master. The association mechanism used for Team Master is the same mechanism used for Managed Master. The Master Path attribute of a bundle, which indicates what master the bundle will be connected to, must be set. See Linking a bundle to a master for more information.

Plugins and Plugin Catalogs coming from creation recipes, which are unique to Team Master, are ignored when using a Configuration as Code (CasC) for Masters bundle for a Team Master. The Configuration as Code (CasC) for Masters bundle takes precedence over the creation recipe values (even though other parameters in recipes are still applied, like provisioning configuration).

When initializing a Managed Master using CloudBees CI on modern cloud platforms, system properties can be added in the Provisioning options when the Master is being created. You can add the same recurrencePeriod property to the Java Options section in the UI. For example, to check for updates every 5 minutes add the Java Option highlighted in red in the screenshot below:

Adding `recurrencePeriod` property to Java Options in UI

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 casc-bundle-link.yaml file content to the clipboard.

    • Download the casc-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.

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). The casc-bundle-link.yaml file needs to be updated with the new token.

As described in other sections, the casc-bundle-link.yaml 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 casc-bundle-link.yaml file.

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

Determining plugin compatibility

All CloudBees Assurance Program (CAP) Tier 1 and Tier 2 plugins are compatible with Configuration as Code (CasC) for Masters at this time; however, they are not all configurable. See Tier 1 and Tier 2 plugins support for Configuration as Code for a list of configurable plugins.

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

Plugin Catalog limitations in CasC

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 CI 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 Knowledge Base article, for guidance on setting up CloudBees CI 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.

CasC API endpoints

Configuration as Code (CasC) for Masters has several HTTP endpoints for retrieving and updating CasC configurations.

CasC CLI commands

Configuration as Code (CasC) for Masters has several CLI commands for retrieving and updating CasC configurations.

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 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 casc-bundle-link.yaml file. To authenticate the request, you will also need to provide the token value from the casc-bundle-link.yaml file as an HTTP header named X-CasC-Token.

Example request with authentication token

curl -v -H "X-CasC-Token: abc123de-f456-7891-gh23-i4jkl45m6n7o" \
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 (CasC) for Masters).