i wanted to run code like this , basically i wanted to run two stages in parallel and also the commands in those stages should run in parallel in itself.
is there a way to do this in declarative pipeline, please let me know.
To me, in theory, it is possible to run two stages in parallel and have the commands in those stages run in parallel using the Declarative Pipeline syntax. Your example is already using the parallel keyword, which is used to run multiple stages in parallel.
To run commands in parallel within a stage, you could use the parallel keyword again within the steps block of the stage. Here is an updated version of your pipeline that should demonstrate this:
In this updated version, the second stage now has a steps block, within which there is a parallel keyword that runs two commands ("two" and "three" ) in parallel. Note that the parallel keyword is used twice: once at the top level to run the two stages in parallel, and once within the steps block to run the two commands in parallel within the second stage.
Thanks for the response @poddingue ,
tried executing the code you pasted , but seems again same issue, can use parallel only once.
might be in declarative pipeline this is not possible, need to mix some script as well.
need to check.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 15: Parallel stages or branches can only be included in a top-level stage. @ line 15, column 17.
echo âaaa1â
@poddingue, your solution works but only shows one stage âABCâ in the dashboard. Would it be possible to still make the parallel tasks âstagesâ that show up in the jenkins dashboard?
When I try to replace:
âfirstâ: {
by:
stage(âfirstâ) {
It breaks with:
java.lang.IllegalArgumentException: Expected named arguments but got [null, {one={two=null, three=null}}]
To make the parallel tasks show up as stages in the Jenkins dashboard, you need to use the stage directive inside the parallel block correctly. Each parallel branch should be wrapped in a stage block.