Jenkins declarative pipeline 1.3 run parallel for all jobs
Asked Answered
A

0

0

I have setup a pipeline project similar to https://jenkins.io/doc/book/pipeline/syntax/#parallel-stages-example and it works fine.

But I have created the same project for different jobs, so rather than creating new jobs can I run for loop for all jobs e.g. jobs = [job1, job2, job3] and run above pipeline code for different jobs.

Something similar to https://jenkins.io/doc/book/pipeline/syntax/#script-example

Can I use a for loop or similar logic to run a declarative pipeline?

I found similar question but not sure how to modify fo this Is it possible to create parallel Jenkins Declarative Pipeline stages in a loop?

Adjunction answered 29/8, 2018 at 21:8 Comment(7)
I am trying to add into declarative syntax so I can add this to Shared LibraryAdjunction
Is it possible to create parallel Jenkins Declarative Pipeline stages in a loop? Max's answer does it exactly how you want it ...Just copy the same thing and replace ["JobA", "JobB", "JobC"] to [job1, job2, job3] ...it will workJeraldinejeralee
You can check github.com/jenkins-infra/pipeline-library/blob/master/vars/… and get the idea of how it's done in Jenkins itself by using a Map, I tried it my self and I came up with a weird error popping up, you might succeed though. Let me know :).Walloping
@rohitthomas If I tried as Max's answer won't it be Scripted Pipeline syntax? If I'm using def method, and I will have to add all declarative methods in def method such as agent, environment etc. I thought you can't use def method with 1.3 syntaxAdjunction
this is the format I am looking at jenkins.io/blog/2018/07/02/…, not finding any example how to incorporate for loop with this, any pointers are appreciatedAdjunction
Where exactly are you facing the issue ... I tried it based on the format you wanted with Max's answer it is working fine and Declarative is built on top of Scripted pipeline so def will work :)Jeraldinejeralee
hmm I thought if I have to move code to Shared library i.e. under def call { pipeline {}} I can't have other def method,Adjunction

© 2022 - 2024 — McMap. All rights reserved.