remove unwanted file from src

parent 83a71eaf
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')
}
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