Search code examples
jenkinsjenkins-pipelinejenkins-plugins

How to copy parameters from one pipeline to another without copying entire pipeline?


On our team, only few people have Jenkins access to perform admin operations as it is Production Jenkins server which developers continuously use for builds.

Sometimes I have to enhance any pipeline or fix issues of pipeline. For that admin has created one pipeline for me so I can add code there and test it. I am suppose to use only that pipeline to test anything.

But I test different pipelines, each pipelines has different parameters list. In this case, I've to add parameters one by one and copying all details of that parameter like Groovy Script, default value etc. which takes lot of time.

Is there any way/plugin using which we can simply copy only parameters from one pipeline to other?


Solution

  • I think you should know each job has a config.xml which represents the job configuration. You can get it by <job_url>/config.xml.

    1. Get the config.xml of the job you want to debug, then extract the xml block for job parameters from the config.xml

    2. Prepare an empty structure config.xml, inject the job parameters' xml block into the empty config.xml

    3. Call Jenkins Rest API to update/save the config.xml to your debug job, then your debug job has target job's params.

    You can write a script to implements above 3 steps.