groovy - Execute String as Code in Jenkins Pipeline -
i want execute multiple parallel steps in jenkins pipeline. variables need given through arraylists. want build code via string builder , loop. after want execute string code
pseudocode:
sb << try{ \n for(i=0; i<tmp; i++) { sb << parallel( build variable{ def buildjobname = build job: buildjobvariable, parameters: [ string(name: 'parametername', value: parameter) ] } } sb << catch(e){ (...) } but how able execute this? tried groovyshell.evaluate(sb.tostring()) results in following error:
hudson.remoting.proxyexception: groovy.lang.missingmethodexception: no signature of method: java.lang.class.evaluate() applicable argument types: (java.lang.string)
we use groovy hash define parallel steps , execute them in 1 parallel statement:
def tests = ["test1", "test2", "test3", "test4"]; try { def branches = [:]; (int = 0; < tests.size(); i++) { def test = tests[i]; branches["$test"] = { try { env.test = test; build job: 'build_job', parameters: [string(name: 'name', value: test)] } catch (err) { currentbuild.result = 'failure'; } } } parallel branches } each element in branches hash 1 parallel execution path.
Comments
Post a Comment