added jenkins jobDSL files

parent e5395305
git:
branchBaseDeployment:
release.2020.09:
env: dit1
promoteTo: eqa1
enabled: false
release.2020.10:
env: dit3
promoteTo: eqa3
enabled: false
release.2020.11:
env: dit2
promoteTo: eqa2
enabled: false
release.2020.12:
env: dit1
promoteTo: eqa1
enabled: false
release.2020.13:
env: dit3
promoteTo: eqa3
enabled: false
\ No newline at end of file
package com.example
class CreateJobs{
public Boolean createPipelineJob(String jobName, String repoUrl, String credentialsID, String srcBranch, String jenkinsfilePath){
pipelineJob(jobName) {
definition {
cpsScm {
scm {
git {
remote {
name(jobName)
url(repoUrl)
credentials(credentialsID)
}
branch(srcBranch)
}
scriptPath(jenkinsfilePath)
}
}
}
}
}
public Boolean createMultibranchPipelineJob(){
multibranchPipelineJob(String jobName, String repoUrl, String credentialsID, String srcBranch, String jenkinsfilePath, List srcBranches) {
branchSources {
git {
remote {
name(jobName)
url(repoUrl)
credentials(credentialsID)
}
includes(srcBranches)
}
scriptPath(jenkinsfilePath)
}
}
}
public Boolean createFolder(String foldername){
folder(foldername) {
displayName(foldername)
description(foldername + " folder")
}
}
}
\ No newline at end of file
package com.example
class ReleaseCheck {
void checkExistence(String branch_name, String yaml_path) {
appendIfNotExist(branch_name,yaml_path)
}
def appendIfNotExist(String buildName, String fileName){
// Opening the File
yamlFile = new File(fileName)
// Yaml Reader
def ys = new YamlSlurper()
// Parsing the YAML and checking if Branch name exists
yamlFile.withReader { reader ->
def yaml = ys.parse(reader)
def git_base_branch_to_deploy = yaml.git.branchBaseDeployment
if ( git_base_branch_to_deploy["$buildName"]) {
println "Branch Name to deploy Already Exists"
}else {
println "The branch name $buildName does not exist, appending in the YAML file"
// Append in the File as It doesn't exist
appendNew(buildName)
}
}
}
// A function to append new banch build name according to the conditions
def appendNew(String newBuildName) {
// Data to be appended, will be defined by conditions
def config
// YamlBuild to convert Groovy Objects to Yaml
def yaml = new YamlBuilder()
// End Result String to be Appended in the File
def end_result
// Conditions to design the YAML object
if (newBuildName.substring(0, 7) == "release"){
config = ["$newBuildName": [env: "dit1", promoteTo: "eqa1", enabled: true]]
yaml(config)
end_result = yaml.toString()
}else if (newBuildName.substring(0, 7) == "develop"){
config = ["$newBuildName": [env: "dit2", promoteTo: "eq2", enabled: true]]
yaml(config)
end_result = yaml.toString()
}else if(newBuildName.substring(0, 7) == "feature"){
config = ["$newBuildName": [env: "dev1", promoteTo: "dev2", enabled: true]]
yaml(config)
end_result = yaml.toString()
}else {
// Handle any other release, other than: release, develop and feature
config = ["$newBuildName": [env: "dev1", promoteTo: "dev2", enabled: true]]
yaml(config)
end_result = yaml.toString()
}
// As it generates a new Yaml Document, remove the firstline
end_result = end_result.replace('---', '')
// Replace 2 spaces with 6 spaces for the children inside <branch_name>
end_result = end_result.replace(" ", " ")
// Append 4 space characters in the first line
// Some Shadowing
end_result.eachMatch("$newBuildName") {ch -> end_result = end_result.replace(ch, " "+ch)}
// Append the End Result string to the YAML file
yamlFile.append(end_result)
}
// Function Usage appendIfNotExists('Branch Name (Can only be: release, develop, feature)', 'FileName to read data from and append data to')
}
import com.example.ReleaseCheck
import com.example.CreateJobs
//ReleaseCheck rc = new ReleaseCheck().checkExistence(release,"../resources/commonConfig.yaml")
CreateJobs job = new CreateJobs().createFolder("hello")
\ No newline at end of file
import ""
def call(String filepath) {
node {
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment