PART 2 - How To generate Multiple Stage GitLab Yaml File Using Python Script

Pubblicato il: 05 marzo 2024
sul canale di: Devops Zplus
491
12

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


In questa pagina del sito puoi guardare il video online PART 2 - How To generate Multiple Stage GitLab Yaml File Using Python Script della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Devops Zplus 05 marzo 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 491 volte e gli è piaciuto 12 spettatori. Buona visione!