Triggering Pipeline in loop with different parameter in sequence

233 Views Asked by At

I read about sharing standard pipeline for multiple projects here

I have a use case where i want to run pipeline template by multiple data in a loop.This pipeline should run sequentially. Here is the code :

//Jenkinsfile
    startPipeline()
def startPipeline(){
    for(i = 0 ; i < 3; i++)
        myPipeline(name : "Hello${i}")
}

I have a Pipeline Template as follows :

//vars/myPipeline.groovy
def call(Map pipelineParams){
    pipeline {
        agent any
        stages {
            stage('print Hello') {
                steps {  echo "${pipelineParams.name}"  }
            }
        }
    }
}

Expected is to run pipelines in sequence. When i try this i get exception Partial Exception log below

java.lang.IllegalStateException: Only one pipeline { ... } block can be executed in a single run.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
0

There are 0 best solutions below