What you’ll learn
- Installing the Configuration as Code plugin
- Where JCasC looks for configuration files and environment variables
- Viewing the auto-generated YAML export
- Editing and applying JCasC YAML on the controller
- Best practices, validation, and troubleshooting
Installation and official docs
Install the plugin from Manage Jenkins → Manage Plugins → Available → Configuration as Code. Official resources:- Plugin page: https://plugins.jenkins.io/configuration-as-code/
- Examples & repo: https://github.com/jenkinsci/configuration-as-code-plugin
Common configuration locations and environment variables
Example environment snippet (for clarity):
- View the current configuration exported to YAML (auto-generated from the running instance).
- Point Jenkins to a file path, HTTP(S) URL, or Git repository with the YAML and apply it.
- Download the current configuration, reload a configuration, or inspect links to documentation and the JSON schema.
Viewing the current configuration (auto-generated YAML)
When you click “View Configuration” JCasC renders a comprehensive YAML representation of the running Jenkins instance. The YAML includes core settings, tool installations, credentials, plugin global configuration (underunclassified), and more.
Representative excerpt for top-level and core settings:
Credentials representation and sensitive data
Credentials are included in the YAML export in declarative form. Sensitive values appear as encrypted blobs or hashed tokens in the generated YAML — the real export hides plaintext secrets. Representative credentials excerpt (sensitive fields shown as encrypted blobs in real exports):Never store raw plaintext secrets in repository-controlled JCasC YAML. Use Jenkins Credentials, external secret stores, or encrypted credentials. If you must store secrets, ensure they are encrypted and access is tightly controlled.
What else is included in the YAML export
The JCasC export can include:- Jenkins core configuration: agent protocols (JNLP, Connect), authorization strategy (Global Matrix, etc.), security realm, system message, node definitions, health monitors, primary view.
- Unclassified section: plugin-specific global configurations such as audit trail, Git servers, SonarQube, Slack notifier, Prometheus, etc.
- Tools: Git, Maven, Node.js, SonarQube scanner, Dependency-Check, and other tool installers.
Working with a JCasC YAML file on the controller
A common workflow is to export the YAML, edit it, and place the edited file on the Jenkins controller (often under$JENKINS_HOME or a mounted volume). Then configure JCasC to point to that file.
Quick example workflow on the Jenkins controller:
jenkins-casc.yaml (fragment):
- On the Configuration as Code page, set the “Configuration source” to a path or URL Jenkins can read, for example:
file:///var/lib/jenkins/JENKINS_BACKUP/jenkins-casc.yaml- or just
jenkins-casc.yamlif the plugin can resolve it in your deployment.
- Click “Apply new configuration.” The plugin will validate the YAML first.
- If the YAML is valid the plugin will report success and show the timestamp when it was loaded.
- Refresh the Jenkins UI to confirm changes (e.g., updated system message).
JSON schema, downloads, and authoring help
- The Configuration as Code page lets you download the current YAML.
- A JSON schema is available and useful for tooling, editors, and programmatic validation of JCasC YAML.
Troubleshooting and validation tips
- Always validate YAML before applying. The JCasC page performs validation and lists problems.
- Check
jenkins.logfor stack traces if applying a configuration fails during runtime. - When a plugin adds new global settings, reconciling YAML may require updating your config or using plugin-specific sections under
unclassified. - For large changes, apply incrementally and verify each step in the UI.
Best practices
Keep your JCasC YAML in version control (Git). Avoid storing raw secrets in YAML; use Jenkins Credentials or an external secrets manager. Use the JCasC JSON schema and plugin documentation when authoring complex configurations to minimize validation errors and drift.
Summary
Jenkins Configuration as Code (JCasC) converts the GUI-driven configuration surface area of Jenkins and many plugins into a declarative YAML format. You can export the current configuration, store it in version control, edit it for reproducible changes, and instruct Jenkins to apply a configuration file. For non-trivial Jenkins installations with many plugins, credentials, tools, and cloud integrations, JCasC improves maintainability and reproducibility. Further reading and references:- Jenkins Configuration as Code (plugin): https://plugins.jenkins.io/configuration-as-code/
- JCasC GitHub repository and examples: https://github.com/jenkinsci/configuration-as-code-plugin
- Jenkins documentation: https://www.jenkins.io/doc/