diff --git a/first-class-pipeline/src/com/freeleaps/devops/EnvironmentVars.groovy b/first-class-pipeline/src/com/freeleaps/devops/EnvironmentVars.groovy new file mode 100644 index 00000000..45af367d --- /dev/null +++ b/first-class-pipeline/src/com/freeleaps/devops/EnvironmentVars.groovy @@ -0,0 +1,38 @@ +package com.freeleaps.devops + +import com.freeleaps.devops.enums.ServiceLanguage + +class EnvironmentVars { + def steps + + EnvironmentVars(steps) { + this.steps = steps + } + + def injectVars(Map configurations) { + steps.env.SERVICE_NAME = "${configurations.SERVICE_NAME}" + if (steps.env.SERVICE_NAME == null || steps.env.SERVICE_NAME.isEmpty()) { + steps.error("SERVICE_NAME is required") + } + + steps.env.SERVICE_LANG = ServiceLanguage.parse("${configurations.SERVICE_LANG}") + if (steps.env.SERVICE_LANG == ServiceLanguage.UNKNOWN) { + steps.error("Unknown service language: ${configurations.SERVICE_LANG}") + } + + steps.env.SERVICE_GIT_REPO = "${configurations.SERVICE_GIT_REPO}" + if (steps.env.SERVICE_GIT_REPO == null || steps.env.SERVICE_GIT_REPO.isEmpty()) { + steps.error("SERVICE_GIT_REPO is required") + } + + steps.env.SERVICE_GIT_BRANCH = "${configurations.SERVICE_GIT_BRANCH}" + if (steps.env.SERVICE_GIT_BRANCH == null || steps.env.SERVICE_GIT_BRANCH.isEmpty()) { + steps.error("SERVICE_GIT_BRANCH is required") + } + + steps.env.ENVIRONMENT_SLUG = "${configurations.ENVIRONMENT_SLUG}" + if (steps.env.ENVIRONMENT_SLUG == null || steps.env.ENVIRONMENT_SLUG.isEmpty()) { + steps.error("ENVIRONMENT_SLUG is required") + } + } +} \ No newline at end of file diff --git a/first-class-pipeline/src/com/freeleaps/devops/SourceFetcher.groovy b/first-class-pipeline/src/com/freeleaps/devops/SourceFetcher.groovy new file mode 100644 index 00000000..74b764ec --- /dev/null +++ b/first-class-pipeline/src/com/freeleaps/devops/SourceFetcher.groovy @@ -0,0 +1,13 @@ +package com.freeleaps.devops + +class SourceFetcher { + def steps + + SourceFetcher(steps) { + this.steps = steps + } + + def fetch(config) { + // TODO: Implement me! + } +} \ No newline at end of file diff --git a/first-class-pipeline/src/com/freeleaps/devops/enums/ServiceLanguage.groovy b/first-class-pipeline/src/com/freeleaps/devops/enums/ServiceLanguage.groovy new file mode 100644 index 00000000..9daeb91e --- /dev/null +++ b/first-class-pipeline/src/com/freeleaps/devops/enums/ServiceLanguage.groovy @@ -0,0 +1,27 @@ +package com.freeleaps.devops.enums + +@CompileStatic +enum ServiceLanguage { + + PYTHON('Python'), + NODE('Node (JS,TS)'), + UNKNOWN('Unknown') + + final String language + + ServiceLanguage(String language) { + this.language = language + } + + ServiceLanguage parse(String language) { + switch (language) { + case 'Python': + return PYTHON + case 'Node (JS,TS)': + return NODE + default: + return Unknown + } + } + +} diff --git a/first-class-pipeline/tests/Jenkinsfile b/first-class-pipeline/tests/Jenkinsfile new file mode 100644 index 00000000..092f95c2 --- /dev/null +++ b/first-class-pipeline/tests/Jenkinsfile @@ -0,0 +1,6 @@ +#!groovy + +library 'first-class-pipeline' + def configurations = [:] + +pipelineCall(configurations) \ No newline at end of file diff --git a/first-class-pipeline/vars/pipelineCall.groovy b/first-class-pipeline/vars/pipelineCall.groovy new file mode 100644 index 00000000..7c681406 --- /dev/null +++ b/first-class-pipeline/vars/pipelineCall.groovy @@ -0,0 +1,51 @@ +#!groovy + +import com.freeleaps.devops.EnvironmentVars +import com.freeleaps.devops.SourceFetcher + +def call(Map configurations) { + def environmentVars = new EnvironmentVars(this) + + pipeline { + agent any + options { + buildDiscarder(logRotator(numToKeepStr: '25')) + timeout(time: 30, unit: 'MINUTES') + ansiColor('xterm') + timestamps() + } + + stages { + + stage("Source Codes Checkout") { + steps { + scripts { + var sourceFetcher = new SourceFetcher(this) + sourceFetcher.fetch(configurations) + } + } + } + + stage("Prepared Environment Variables") { + steps { + script { + environmentVars.injectVars(configurations) + } + } + } + + stage("Commit Linting If Enabled") { + steps { + scripts { + enabled = "${configurations.COMMIT_MESSAGE_LINT_ENABLED}" + + if (enabled == "true") { + print("Commit Linting is enabled") + } + } + } + } + + } + } +} \ No newline at end of file