116 lines
5.8 KiB
Groovy
116 lines
5.8 KiB
Groovy
pipeline {
|
|
agent {
|
|
kubernetes {
|
|
yamlFile "resources/org/meesho/${env.INFRA_ENV}-pod.yaml"
|
|
defaultContainer 'devops-tools'
|
|
}
|
|
}
|
|
|
|
environment {
|
|
GITHUB_CRED = 'svc-devops-meesho'
|
|
}
|
|
|
|
parameters {
|
|
string(name: 'repo_name', defaultValue: '', trim: true, description: 'Please enter repo name.')
|
|
string(name: 'branch_name', defaultValue: 'main', trim: true, description: 'Please enter branch name.')
|
|
choice(name: 'jdk_version', choices: ['jdk8', 'jdk11', 'jdk17', 'jdk21', 'jdk25'], description: 'Please select JDK Version. For adding new JDK Version, please contact DevOps Team.')
|
|
booleanParam(name: 'skip_tests', defaultValue: true, description: 'This option will skip tests while mvn build.')
|
|
booleanParam(name: 'sonar_scan', defaultValue: true, description: 'This option will perform static analysis of code via SonarQube.')
|
|
booleanParam(name: 'sub_modules', defaultValue: false, description: 'This option will enable the use of Git submodules.')
|
|
}
|
|
|
|
stages {
|
|
stage('Validate Params') {
|
|
steps {
|
|
script {
|
|
echo '####################### Validating Parameters ###########################'
|
|
echo "Repo Name: ${params.repo_name}"
|
|
echo "Branch Name: ${params.branch_name}"
|
|
echo "JDK Version: ${params.jdk_version}"
|
|
echo "Skip Tests: ${params.skip_tests}"
|
|
echo "Sonar Scan: ${params.sonar_scan}"
|
|
echo "Sub module: ${params.sub_modules}"
|
|
}
|
|
}
|
|
}
|
|
stage('Build') {
|
|
steps {
|
|
ansiColor('xterm') {
|
|
script {
|
|
sh 'whoami'
|
|
def extra_args = ''
|
|
if (env.INFRA_ENV == 'prd') {
|
|
jfrog_repo = '-DuseProdRepo=true'
|
|
}
|
|
else {
|
|
jfrog_repo = '-DuseTestRepo=true'
|
|
}
|
|
if (skip_tests.toBoolean()) {
|
|
extra_args = '-DskipTests'
|
|
}
|
|
withCredentials([gitUsernamePassword(credentialsId: "${env.GITHUB_CRED}", gitToolName: 'git-tool')]) {
|
|
sh "git clone -b ${branch_name} https://github.com/Meesho/${repo_name}.git"
|
|
}
|
|
if (sub_modules.toBoolean()) {
|
|
dir("${repo_name}") {
|
|
withCredentials([gitUsernamePassword(credentialsId: "${env.GITHUB_CRED}", gitToolName: 'git-tool')]) {
|
|
sh(script:'git submodule init && git submodule update && git submodule update --recursive --remote')
|
|
}
|
|
}
|
|
}
|
|
|
|
def effective_jdk = params.jdk_version
|
|
dir("${repo_name}") {
|
|
if (fileExists('config.yaml')) {
|
|
def config = readYaml file: 'config.yaml'
|
|
def dv = config?.dockerBuildVersion?.toString() ?: ''
|
|
def matcher = (dv =~ /maven-.*-jdk-(\d+)/)
|
|
if (matcher) {
|
|
effective_jdk = "jdk${matcher[0][1]}"
|
|
echo "Using JDK from config.yaml dockerBuildVersion: ${dv} -> ${effective_jdk}"
|
|
}
|
|
}
|
|
}
|
|
if (effective_jdk == 'jdk25') {
|
|
env.JAVA_HOME = '/usr/lib/jvm/java-25-openjdk-amd64/'
|
|
}
|
|
else if (effective_jdk == 'jdk21') {
|
|
env.JAVA_HOME = '/usr/lib/jvm/java-21-openjdk-amd64/'
|
|
}
|
|
else if (effective_jdk == 'jdk17') {
|
|
env.JAVA_HOME = '/usr/lib/jvm/java-17-openjdk-amd64/'
|
|
}
|
|
else if (effective_jdk == 'jdk11') {
|
|
env.JAVA_HOME = '/usr/lib/jvm/java-11-openjdk-amd64/'
|
|
}
|
|
else {
|
|
env.JAVA_HOME = '/usr/lib/jvm/java-8-openjdk-amd64/'
|
|
}
|
|
echo "Resolved JAVA_HOME: ${env.JAVA_HOME} (effective_jdk: ${effective_jdk})"
|
|
dir("${repo_name}") {
|
|
echo '####################### Building Artifacts ###########################'
|
|
sh """
|
|
pwd
|
|
ls -al
|
|
mvn -v
|
|
mvn clean install ${extra_args}
|
|
"""
|
|
if (sonar_scan.toBoolean()) {
|
|
withSonarQubeEnv('sonarqube-test') {
|
|
echo '####################### Performing Sonar Scan ###########################'
|
|
sh(script: "JAVA_HOME='${env.JAVA_HOME}' mvn sonar:sonar -Dsonar.branch.name=${branch_name} -Dsonar.projectName=${repo_name}")
|
|
}
|
|
}
|
|
else {
|
|
echo '####################### Skipping Sonar Scan ###########################'
|
|
}
|
|
echo '####################### Pushing Artifacts to Jfrog ###########################'
|
|
sh(script: "mvn package deploy -DskipTests=${skip_tests} ${jfrog_repo}")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|