I want to use a python script as input to create stages in jenkins pipeline


{'job-name': 'Test1', 'action': 'a', 'targetname': 'x'}
{'job-name': 'Test2', 'action': 'b', 'targetname': 'y'} 
{'job-name': 'Test3', 'action': 'c', 'targetname': 'z'}

The output of the above python script is a dictionary.

How to run this python script in Jenkins pipeline in a stage and how to store the output and use the output to define further stages


stage(Test1) {

stage(Test2) {

stage(Test3) {


Extract only 'value' of a particular 'key' from the output of python script to define stages in Jenkins pipeline.

How to execute it in Jenkins groovy as declarative pipeline ?

  • Did you solve your requirement?
    – JRichardsz
    May 28 at 17:12

1 Answer 1


This was already asked and answered over on StackOverflow.

TL;DR: you must use Scripted Pipeline; Declarative does not support dynamic stages. Here is a copy-paste of the top answer:

Use the scripted syntax that allows more flexibility than the declarative syntax, even though the declarative is more documented and recommended.

For example stages can be created in a loop:

def tests = params.Tests.split(',')
for (int i = 0; i < tests.length; i++) {
    stage("Test ${tests[i]}") {
        sh '....'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.