Integrating with Jenkins

5 minute read

The Jenkins plugin adds a build step that downloads flag configurations for a given CloudBees Feature Management environment, allowing you to compare the environment with previous builds, and more quickly determine if a feature flag was the cause of build failure. The step can either be added to a freestyle project, or as a declarative pipeline step.

The snippet generator allows you to generate snippets that can be added to your Jenkins declarative pipeline builds.

The Freestyle approach uses the CloudBees Feature Management Jenkins plugin as a part of build steps within the Jenkins continuous integration workflows.

Once installed, the CloudBees Feature Management Jenkins plugin is managed in the Jenkins Plugin Manager. Deleting the plugin removes the binary from your Jenkins Home.

Each approach integrates with CloudBees Feature Management via the REST API to fetch the flag configurations at build-time. For more information, refer to the REST API documentation.

Integrating with Jenkins

How to integrate with Jenkins, and advantages.

Watch the video

Events for each approach are logged in the CloudBees Feature Management Audit log. For more information, refer to the CloudBees Feature Management Audit log documentation.

This page describes how to do the following:

  • (Required step) Install the CloudBees Feature Management Jenkins plugin.

  • Verify the plugin is installed and enabled.

  • (Required step) Retrieve your API token from CloudBees Feature Management.

  • Create a Pipeline project.

  • Create a Freestyle project.

  • Uninstall the CloudBees Feature Management Jenkins plugin.

Installing the CloudBees Feature Management Jenkins plugin

The plugin is downloaded from within the Jenkins Plugin Manager.

To download the plugin:

  1. From the Jenkins Home page, from the left pane, select Manage Jenkins.

  2. Under System Configuration, select Manage Plugins.

  3. In the Plugin Manager screen, select the Available tab.

  4. From the top left corner of your screen, enter CloudBees Feature Management into the Search.

  5. Place a check next to the CloudBees Feature Management plugin.

  6. Select Install without restart.

    Selecting Install without restart

    The installation plugins for the CloudBees Feature Management Jenkins integration is complete when marked with a circled green check and Success indicator.

    Success

The CloudBees Feature Management Jenkins plugin is installed and enabled. You can now begin creating your Freestyle project.

Verifying the plugin is installed and enabled

You can verify the CloudBees Feature Management Jenkins plugin is installed using the Jenkins Plugin Manager.

To verify the plugin is installed:

  1. From the Jenkins Home page, from the left pane, select Manage Jenkins.

  2. For System Configuration, select Manage Plugins.

  3. In the Plugin Manager screen, select the Installed tab.

  4. From the top right corner of your screen, enter CloudBees Feature Management into the Search.

    The enabled toggle.
  5. To the right of the CloudBees Feature Management plugin, verify that the Enabled switch is toggled on.

Retrieving your API token from CloudBees Feature Management

The CloudBees Feature Management API token is required to connect Pipeline and Freestyle projects to CloudBees Feature Management.

The User token creates the secret text credential which Jenkins will use to download the configuration from the CloudBees REST API .

To retrieve your User token from CloudBees Feature Management:

  1. From the CloudBees Feature Management Home page, on the left pane, select App settings.

  2. In the Integrations tab under API, select Show to display the User token, then select Copy.

You are now ready to add your User token to your Jenkins projects.

Creating a Pipeline project

Integrating CloudBees Feature Management within a Jenkins Pipeline project requires a pipeline step to be added to your code within the continuous integration environment.

To create a Pipeline project:

  1. From the Jenkins Home page, from the left pane, select New Item.

  2. From the center of your screen, below Enter an item name, enter a project name.

  3. Select Pipeline

  4. Select OK.

    The Project Configuration screen opens.

  5. Scroll to the bottom of the page, and select the Pipeline Syntax link.

    The Snippet Generator screen opens.

  6. In Steps, for Sample Step, select featureMangementConfig: CloudBees Feature Management configuration to generate the code snippet that is required to run that the code plugin runs.

    Use the F shortcut key to jump to the configuration.
  7. For Credentials, select Add  Jenkins  Jenkins credentials provider.

    Selecting the Jenkins Credentials Provider.

    The Jenkins Credentials Provider screen is displayed.

    To configure credentials:

  8. For Kind, select Secret text.

  9. For Secret, paste the User token.

  10. For ID, enter an ID.

    All other fields are optional.
  11. Select Add to add the credential and return to your project.

    You can now select the User token as a Credential.

  12. For Credentials, select your newly created ID from the dropdown.

    An API Token invalid warning message is displayed if an invalid User token is selected.
  13. For Application select the application.

  14. For Environment choose the environment.

  15. Select Generate Pipeline Script to generate the script.

  16. Copy the script to your clipboard.

    The script is displayed beneath the button.
  17. From the left pane, select Back  Configure to return to the Project Configuration screen.

  18. In the Pipeline tab, for Pipeline  Definition select Pipeline script.

  19. For Script, add your application code, and paste the Pipeline script into the code.

    You can optionally select Try Sample Pipeline and select an option to use example application code.
    The script is displayed beneath the button.
    Figure 1. Adding the Pipeline script to example Hello World code.
  20. Select Save.

The new project can be accessed from the Jenkins > Dashboard. The new flag can be accessed from CloudBees Feature Management.

Creating a Freestyle project

After your CloudBees Feature Management Jenkins plugin has been installed, you can begin creating a Freestyle project. After you create the Freestyle project, you must configure credentials for it.

To create a Freestyle project:

  1. From the Jenkins Home page, from the left pane, select New Item.

  2. From the center of your screen, enter a name below Enter an item name.

  3. Select Freestyle project.

  4. Select OK.

    The project configuration screen opens.

  5. For Build, select Add build step > CloudBees Feature Management configuration.

  6. For Credentials select Add  Jenkins  Jenkins credentials provider.

    The Add Credentials screen is displayed.

    To configure credentials:

  7. For Kind, select Secret text.

  8. For Secret, paste the User token.

  9. For ID, enter an ID.

    All other fields are optional.
  10. Select Add to add the credential and return to your project.

    You can now select the User token as a Credential.

  11. For Credentials, select your newly created ID from the dropdown.

    An API Token invalid warning message is displayed if an invalid User token is selected.
  12. For Application, select the application you would like to connect to.

  13. For Environment, choose the environment.

  14. (Optionally) Select Add build step and repeat the steps to configure an additional build step.

  15. Select Save.

The new project can be accessed from the Jenkins > Dashboard.

Uninstalling the CloudBees Feature Management Jenkins plugin

Deleting CloudBees Feature Management Jenkins plugin removes the plugin binary from your Jenkins Home.

The CloudBees Feature Management Jenkins plugin can be removed from the controller using the Plugin Manager.

To remove the CloudBees Feature Management Jenkins plugin:

  1. From the Jenkins Home page, from the left pane, select Manage Jenkins.

  2. Under System Configuration, select Manage Plugins.

  3. In the Plugin Manager screen, select the Installed tab.

  4. From the top left corner of your screen, enter CloudBees Feature Management into the Search.

  5. To the right of the CloudBees Feature Management plugin, select (X) Uninstall CloudBees Feature Management.

    bumblebee on a flower
  6. If you agree to the information on the screen, select Yes to uninstall the CloudBees Feature Management Jenkins plugin.