Translator for Jenkins declarative and imperative syntax pipelines
Problem to solve
Our customers who are migrating from Jenkins have pipelines that use the newer declarative or imperative syntax (as opposed to JenkinsFiles, a Groovy DSL).
- The Declarative Jenkinsfile - this has the traditional stage and node blocks. This is the most recent format. Also easiest to parse.
- Declarative Jenkinsfile w/ Groovy Library - This is a declarative Jenkinsfile that one each stage/node simply invoked some external Groovy code. The Jenkinsfile just controls the flow.
- The Imperative Jenkinsfile - This is the same as above, except inside the stages it calls exterior functions to Groovy functions. Because of this the pipeline can go forwards and backwards, redoing stages as necessary. It can also include if/and/else login to change the pipeline structure mid-job.
Intended users
Further details
Original discussion thread in meta epic: &2735 (comment 295171884)
From @awaters3:
Declarative Syntax (as opposed to Groovy) pipelines would be a simpler place to start given it inherently has more structure
Declarative is relatively new though - introduced 2-3 yrs ago and initially with a slow up take. My guess is that today the majority of new pipelines would be developed using Declarative, but that the majority still in use would be Groovy based so a declarative only converter would limit use. Stats show around 55k downloads (and growing) of the relevant plugins for declarative though, so not insignificant.
When discussing possibility of automated conversions with companies, always worth finding out which style of pipeline they are using.
Proposal
Write a tool that can read in a declarative Jenkins configuration file and convert it to a valid .gitlab-ci.yml.
This could take advantage of dynamic child pipelines to put the processor in the originator and the job to be run in the triggered child.