Need advice on pipeline structure
I have a deploy job in Jenkins using declarative pipeline syntax with a kubernetes pod where I can select from a list of environments to deploy to.
- dev
- dev-1
- dev-2
- test
- test-1
- test-2
- prod
The main deploy job's stages:
- Check the code
- Runs tests
- Calls a separate AMI build
- Deploys
I would like to create two more jobs, one to deploy to all test at the same time, and one to deploy to all dev at the same time.
I was looking at maybe using and calling the main deploy job from the "deploy to x" job. Basically passing in "dev", "dev-1", etc as parameters
So it would be something like (I think):
stage('Deploy to all dev') { parallel { stage('Deploy dev') { build(job: 'main-deploy', parameters: [ string(name: 'env', value: 'dev') ..etc ]) } stage('Deploy to dev-1') { build(job: 'main-deploy', parameters: [ string(name: 'env', value: 'dev-1') ..etc ]) } } } However, I want to avoid recreating the AMI every time if it already exists. But if it doesn't exist, I only want it created once. But if they all kick off in parallel, the AMI build will get called everytime. I'm new to all of this and I'm not sure what is the best way to structure it in this scenario.

