pipeline { agent any tools { maven 'maven' // The name defined in Manage Jenkins > Global Tool Configuration } parameters { string(name: 'serviceName', defaultValue: 'my-service', description: 'Service Name') string(name: 'interfaceName', defaultValue: 'B_IN_A_B', description: 'Interface Name') string(name: 'interfaceType', defaultValue: 'Batch', description: 'Interface Type') string(name: 'repositoryName', defaultValue: 'bwceApp', description: 'Repository Name') string(name: 'repositoryProject', defaultValue: 'project', description: 'Repository Project') } environment { MAVEN_SETTINGS = credentials('maven-settings') // Jenkins credential for settings.xml GIT_PAT = credentials('git-pat') // Jenkins credential for PAT } stages { stage('Checkout') { steps { script { checkout scm } } } stage('Prepare Environment') { steps { script { echo "Service Name: ${params.serviceName}" echo "Interface Name: ${params.interfaceName}" echo "Repository Name: ${params.repositoryName}" echo "Interface Type: ${params.interfaceType}" echo "Repository Project: ${params.repositoryProject}" } } } stage('Generate POM') { steps { script { writeFile file: 'pom.xml', text: ''' 4.0.0 com.example example-project 1.0-SNAPSHOT pom ''' } } } stage('Build with Maven') { steps { script { sh "mvn -s ${MAVEN_SETTINGS} -P BWCE archetype:generate -DartifactId=${params.serviceName} -Dk8sEnabled=N -DInterfaceType=${params.interfaceType} -DInterfaceNames=${params.interfaceName} -Dpackage='com.tibco.bw' -DgroupId='com.tibco.bw' -DarchetypeArtifactId=service-archetype -DarchetypeGroupId=onemdw.bwce -DarchetypeVersion=1.1.0-SNAPSHOT -DinteractiveMode=false" } } } stage('Generate YAML File') { steps { script { def yamlContent = """apiVersion: backstage.io/v1alpha1 kind: Component metadata: name: "${params.serviceName}" title: "${params.serviceName}" description: "${params.serviceName} description" annotations: sonarqube.org/project-key: ${params.repositoryProject}.${params.repositoryName} backstage.io/techdocs-ref: dir:. links: - url: "http://google.com" title: Solution Design Document (SDD) icon: docs tags: - bwce spec: type: service lifecycle: experimental owner: CEVA_TIBCO_TEAM""" writeFile file: "catalog-info.yaml", text: yamlContent } } } stage('Push to New Repository') { steps { script { sh """ git config --global user.email "tpadmin@tibco.com" git config --global user.name "TIBCO" if [ -d "${params.repositoryName}" ]; then rm -rf ${params.repositoryName} fi echo ${GIT_PAT} git clone https://${GIT_PAT}@gitlab.com/${params.repositoryProject}/${params.repositoryName}.git git checkout master || git checkout -b master || true cp catalog-info.yaml ${params.repositoryName}/catalog-info.yaml cd ${params.repositoryName} git add . git commit -m "Initial catalog.yaml" git push origin master git checkout -b skeleton cp -r ../${params.serviceName}/* . git add . git commit -m "Initial commit on skeleton branch" git push origin skeleton """ } } } } }