125 lines
4.5 KiB
Groovy
125 lines
4.5 KiB
Groovy
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: '''<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<modelVersion>4.0.0</modelVersion>
|
|
<groupId>com.example</groupId>
|
|
<artifactId>example-project</artifactId>
|
|
<version>1.0-SNAPSHOT</version>
|
|
<packaging>pom</packaging>
|
|
</project>
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
|
|
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: de.dlh.OIP.${params.repositoryProject}.${params.repositoryName}
|
|
backstage.io/techdocs-ref: dir:.
|
|
links:
|
|
- url: "lalala"
|
|
title: Solution Design Document (SDD)
|
|
icon: docs
|
|
tags:
|
|
- bwce
|
|
spec:
|
|
type: service
|
|
lifecycle: experimental
|
|
owner: DH_TEAM_ONEMDW"""
|
|
|
|
writeFile file: "${params.serviceName}/catalog-info.yaml", text: yamlContent
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Push to New Repository') {
|
|
steps {
|
|
script {
|
|
def repoUrl = "gitea:3000/${params.repositoryProject}/${params.repositoryName}.git"
|
|
|
|
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
|
|
|
|
git clone http://${GIT_PAT}@gitlab.com/${params.repositoryProject}/${params.repositoryName}.git
|
|
|
|
cp -r ${params.serviceName}/* ${params.repositoryName}/
|
|
|
|
cd ${params.repositoryName}
|
|
|
|
git checkout -b skeleton
|
|
git add .
|
|
git commit -m "Initial commit on skeleton branch"
|
|
git push origin skeleton
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |