Hello guys You can refer below code.
------------------------------------------------------------------------------------------------------------------------------------------
Step1:- To Create python script e.g create_yml.py
import sys, subprocess
def generate_template(name):
return f"""
stages:
{name}-build
{name}-test
{name}-deploy
{name}-build-job:
stage: {name}-build
image: ubuntu
script:
echo "Script has been generated by python file with build stage"
{name}-test-job:
stage: {name}-test
image: ubuntu
script:
echo "Script has been generated by python file with test stage"
{name}-deploy-job:
stage: {name}-deploy
image: ubuntu
script:
echo "Script has been generated by python file with deploy stage"
"""
def create_job(names):
with open("single_pipeline.yml", "w") as f:
for name in names:
f.write(generate_template(name))
if _name_ == "__main__":
names = sys.argv[1].split()
create_job(names)
--------------------------------------------------------------------------------------------------------------------------------------
Step2: To Create .gitlab-ci.yml file
stages:
setup
trigger
setup:
stage: setup
image: python:3
script:
echo "Executing python script"
python3 create_job.py "python"
artifacts:
paths:
single_pipeline.yml
trigger:
stage: trigger
needs:
setup
trigger:
include:
artifact: single_pipeline.yml
job: setup
On this page of the site you can watch the video online PART 2 - How To generate Multiple Stage GitLab Yaml File Using Python Script with a duration of hours minute second in good quality, which was uploaded by the user Devops Zplus 05 March 2024, share the link with friends and acquaintances, this video has already been watched 491 times on youtube and it was liked by 12 viewers. Enjoy your viewing!