How can I convert an existing Jenkins jobs to DSL Script?

Article ID:203882590
1 minute readKnowledge base

Issue

  • We are in process of taking backup of all existing jobs and we want to convert all existing jenkins jobs to DSL Script to save them in SCM…​

  • Is there a way we can convert all existing jenkins jobs to DSL Script?

Environment

  • CloudBees Jenkins Enterprise

Resolution

If you just want to backup the Jenkins Job configuration, you can use the SCM Sync configuration plugin. It automatically commits every job modification to a SCM.

For DSL scripting, there is either:

  • Jenkins Pipeline: A suite of plugins that lets you orchestrate automation, simple or complex.

  • JobDSL plugin: a Groovy DSL to create and configure job programmatically. JobDSL scripts can be stored in a SCM and job reconfiguration can even be triggered on commit on this repository. The plugin has an extensive documentation on GitHub wiki. It can be difficult to start with but it’s very powerful.

  • Literate plugin: a plugin using a file in the project source to explain on how to build the project.

Unfortunately, none of these plugins can automatically convert existing job configuration to a script. The YAML Project Plugin can do that but the plugin is at its early stage.