NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io



stage('Prerequisites') {
deleteDir()
checkout scm

//branch name derived for rundeck job invocation
println "Branch_Name--"+branchName
Branch_Name=branchName
Branch_trigger=Branch_Name
println "Branch_trigger:-"+Branch_trigger


string branch1 = Branch_Name.split("/")[0] //To derive the branch name for rundeck




def dt1 = sh(returnStdout: true, script: ' date "+%y"').trim()
def int mth1 = sh(returnStdout: true, script: ' date "+%m"').trim()
def String mth2=""
if (mth1.compareTo(10) < 10){
mth2=mth1
mth2=mth2.replace("0","")
println mth2
}
develop12 = branch1.take(1).toUpperCase()


switch (branch1) {
case "develop" :
BuildVersion = dt1+"."+mth2+"."+develop12+"."+BUILD_ID
break;
case "master" :
BuildVersion = dt1+"."+mth2+"."+develop12+"."+BUILD_ID
master_build_only="Y"
break;
case "hotfix" :
BuildVersion = dt1+"."+mth2+"."+develop12+"."+BUILD_ID
Branch_trigger=Branch_Name.replace("/","-")
break;
case "bugfix" :
BuildVersion = dt1+"."+mth2+"."+develop12+"."+BUILD_ID
Branch_trigger=Branch_Name.replace("/","-")
break;
case "release" :
release2 = Branch_Name.split("/")[1] // to derive for version number for release branch

println release2
char someChar = '.';
int count = 0;
for (int i = 0; i < release2.length(); i++) {
if (release2.charAt(i) == someChar) {
count++;
}
}
println count

if (count == 1){
BuildVersion = release2+".0."+BUILD_ID
}
else{
BuildVersion = release2+"."+BUILD_ID
}


Branch_trigger=Branch_Name.replace("/","-")
break;

default:
BuildVersion = dt1+"."+develop12+".0."+BUILD_ID
Branch_trigger = Branch_Name.replace("/","-")
println "Not a develop and release branch"

break;
}
// if (instance_name.trim().equals("flowbank") || instance_name.trim().equals("csa")){
// if (branch1.trim().equals("bugfix")){
// direct_uat_build="Y"
// }
// }

// if ((branch1.trim().equals("feature")) || (branch1.trim().equals("bugfix"))){
// if (direct_uat_build.equals("N")) {
// throw new GroovyRuntimeException("***Feature and Bugfix branches Build and Deployment is not supported****")
// }
// }
println "BuildVersion:-- "+BuildVersion

switch (Application_Deployment_Env){
case "CIT-QA" :
build_version=BuildVersion
break;
case "CIT-GOLD" :
build_version=BuildVersion
break;
case "UAT" :
if ((BuildVersion.trim().equals(build_version.trim()))) {
direct_uat_build="Y"
}
else {
direct_uat_build="N"
}

def Build_version_verify = sh(returnStdout: true, script: "curl -s https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/")
println "This is the current version " +Build_version_verify
if ((!Build_version_verify.trim().contains("${build_version}"))){
echo "*************************************************************************************************************************************************************"
echo "*Build Version is not found in the artifactory, please verify at https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/ **"
echo "*************************************************************************************************************************************************************"
if (direct_uat_build.trim().equals("N")){
throw new GroovyRuntimeException("***Job Failed for above highlighted reason****")
}
}


break;
case "GOLD-QA" :


if ((BuildVersion.trim().equals(build_version.trim()))) {
direct_uat_build="Y"
}
else {
direct_uat_build="N"
}

def Build_version_verify = sh(returnStdout: true, script: "curl -s https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/")
println "This is the current version " +Build_version_verify
if ((!Build_version_verify.trim().contains("${build_version}"))){
echo "*************************************************************************************************************************************************************"
echo "*Build Version is not found in the artifactory, please verify at https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/ **"
echo "*************************************************************************************************************************************************************"
if (direct_uat_build.trim().equals("N")){
throw new GroovyRuntimeException("***Job Failed for above highlighted reason****")
}
}
break;
case "PT" :


if ((BuildVersion.trim().equals(build_version.trim()))) {
direct_uat_build="Y"
}
else {
direct_uat_build="N"
}

def Build_version_verify = sh(returnStdout: true, script: "curl -s https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/")
println "This is the current version " +Build_version_verify
if ((!Build_version_verify.trim().contains("${build_version}"))){
echo "*************************************************************************************************************************************************************"
echo "*Build Version is not found in the artifactory, please verify at https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/ **"
echo "*************************************************************************************************************************************************************"
if (direct_uat_build.trim().equals("N")){
throw new GroovyRuntimeException("***Job Failed for above highlighted reason****")
}
}
break;
case "OAT" :


if ((BuildVersion.trim().equals(build_version.trim()))) {
direct_uat_build="Y"
}
else {
direct_uat_build="N"
}

def Build_version_verify = sh(returnStdout: true, script: "curl -s https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/")
println "This is the current version " +Build_version_verify
if ((!Build_version_verify.trim().contains("${build_version}"))){
echo "*************************************************************************************************************************************************************"
echo "*Build Version is not found in the artifactory, please verify at https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/ **"
echo "*************************************************************************************************************************************************************"
if (direct_uat_build.trim().equals("N")){
throw new GroovyRuntimeException("***Job Failed for above highlighted reason****")
}
}
break;

}

}

stage('Build') {
if (Application_Deployment_Env.trim().equals("CIT-QA") || Application_Deployment_Env.trim().equals("CIT-GOLD") || direct_uat_build.trim().equals("Y")){
def buildJobReturnObj = build job: "S2BV4/s2bv4-ui-core/${Branch_trigger}/BUILD_PARAM1", parameters: ([string(name: 'node_envn', value: node_envn),
string(name: 'build_mode', value: build_mode),
string(name: 'environment', value: environment),
string(name: 'build_version', value: BuildVersion),
string(name: 'cib_ui_core_version',value: cib_ui_core_version)]), propagate: false, wait: true

buildType1="BUILD_PARAM1"
BUILD_ID1=buildJobReturnObj.getNumber()

println "buildJobReturnObj: ${BUILD_ID1} ${buildType1}"

build1_result=buildJobReturnObj.getResult()

if (!build1_result.trim().equals("SUCCESS")) {
throw new GroovyRuntimeException("*****s2bv4-ui-core build failed please check******")
}

}

}

stage('Quality Gate') {
println "Quality gate will be enabled soon"

if ((master_build_only.trim().equals("Y"))) {
echo "*************************************************************************************************************************************************************"
echo "*Build has been done please verify https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/ **"
echo "*************************************************************************************************************************************************************"
throw new GroovyRuntimeException("***Job Failed for above highlighted reason****") }

}


stage('Deployment') {
if (currentBuild.currentResult == 'SUCCESS'){
if (Application_Deployment_Env.trim().equals("GOLD-QA") || Application_Deployment_Env.trim().equals("UAT") || Application_Deployment_Env.trim().equals("PT") || Application_Deployment_Env.trim().equals("OAT")){
artifactlist = ["A"]
sitArray1= sh(returnStdout: true, script: "echo 'https://artifactory.global.standardchartered.com/artifactory/generic-release/s2bnextgen-release/ui/ui-${build_version}-ui-core-${build_version}.zip'")
println sitArray1
artifactlist[0]=sitArray1

println artifactlist[0]
}
if (currentBuild.currentResult == 'SUCCESS'){
//Sending notification to the user who had triggered the job

/* emailext(
attachLog: false,
subject: "Deployment in ${Application_Deployment_Env} Environment has sarted",
body: "Job Name- ${env.JOB_NAME} nn BUILD Number - ${env.BUILD_NUMBER} has started nn BUILD URL - ${env.BUILD_URL}",
to: "${user}",
replyTo: "[email protected]"
) */

//clone the code from ansible repo to trigger the job
sh 'curl https://bitbucket.global.standardchartered.com/projects/S2BV4/repos/s2bv4-ansible/raw/S2BV4NextGen/deploy_path_decider.txt?at=refs%2Fheads%2Ffeature%2Ftestcicd > deploy_path_decider.txt'
def inputFile = readFile "${env.WORKSPACE}/deploy_path_decider.txt"

// def inputFile = readFile "${env.WORKSPACE}/S2BV4NextGen/deploy_path_decider.txt"
println "Input file -"+inputFile
def lines = inputFile.split("n")
urlrundeckjob = lines[11].split("=")[1]
println "Rundeck url-"+urlrundeckjob


//Derives the Rundeck job URL
switch (Application_Deployment_Env) {
case "CIT-QA" :
rundeckjob = lines[14].split(",")[1].split('=')[1]
println rundeckjob
// sanity_pack="CIT"
break;
case "CIT-GOLD" :
rundeckjob = lines[16].split(",")[1].split('=')[1]
println rundeckjob
// sanity_pack="CIT2"
break;
case "UAT" :
rundeckjob = lines[14].split(",")[2].split('=')[1]
println rundeckjob
// sanity_pack="SIT"
BuildVersion=build_version
break;
case "GOLD-QA" :
rundeckjob = lines[16].split(",")[2].split('=')[1]
println rundeckjob
// sanity_pack="SIT2"
BuildVersion=build_version
break;
case "PT" :
rundeckjob = lines[14].split(",")[3].split('=')[1]
println rundeckjob
// sanity_pack="SIT2"
BuildVersion=build_version
break;
case "OAT" :
rundeckjob = lines[14].split(",")[4].split('=')[1]
println rundeckjob
// sanity_pack="SIT2"
BuildVersion=build_version
break;
}


if (Application_Deployment_Env.trim().equals("CIT-QA") || Application_Deployment_Env.trim().equals("CIT-GOLD")){
//fetching the zip files from artifactory
def artifactorySearchRESTPostUrl = "https://artifactory.global.standardchartered.com/artifactory/api/search/buildArtifacts"
def String artifactbranch = "${branchName}".replaceAll("/", "-").trim()
def requestPayload = """
{
"buildName": "${projectName} :: ${repoName} :: ${artifactbranch} :: ${buildType1}",
"buildNumber": "${BUILD_ID1}"
}
"""
println "************************:$requestPayload *************************n"
def response = httpRequest acceptType: "APPLICATION_JSON", contentType: "APPLICATION_JSON", httpMode: "POST", requestBody: "${requestPayload}", consoleLogResponseBody: false, url: "${artifactorySearchRESTPostUrl}"
println "response******************************: $responsen"
if ( response.status == 200 ) {
responseJson = readJSON text: response.content
results = responseJson.results
echo "*****Published build artifacts*****: $results.downloadUri ***********n"
}


//capturing all artifacts and looped to do deployments only for the war files.
artifactlist = results.downloadUri
}
for (item in artifactlist) {
if (item.contains('.zip')) {

//if any zip files are found invokes the rundeck job
// def zipfile = item.trim()
def zipfile = sh(returnStdout: true, script: "basename ${item}").trim()
println zipfile
//throw new GroovyRuntimeException("*****wow it got the task done******")





//Rundeck job invoke
if (currentBuild.currentResult == 'SUCCESS'){
withCredentials([string(credentialsId: 'rundeckAuthToken', variable: 'authTokenRundeck')]) {
def runDeckProject = "S2BV4NextGen"
def runDeckJobId = rundeckjob
def runDeckBaseURL = urlrundeckjob
//set for 20 min(30sec* 40 times) as default as of now
def retries = 40
def timeout = 30
def verbose = "-v"
def args = "-zipfile ${zipfile} -instance_name ${instance_name}"
def runDeckURL = "${runDeckBaseURL}/api/19/job/${runDeckJobId}/run"
def runDeckResponse = sh(returnStdout: true, script: "curl -k ${verbose} --data-urlencode argString="${args}" -H Accept:application/json -H X-Rundeck-Auth-Token:${authTokenRundeck} ${runDeckURL}")
println "Rundeck job run response: ${runDeckResponse}"
def runDeckResponseJson = readJSON text: "${runDeckResponse}"

while (true) {
if (retries == 0) {
error "RunDeck Job Timedout, See: ${runDeckBaseURL}/project/${runDeckProject}/job/show/${runDeckJobId}"
break;
}
def jobStateUrl = "${runDeckBaseURL}/api/19/execution/${runDeckResponseJson.id}/state"
echo "Polling runDeckPollingURL: ${jobStateUrl} ${authTokenRundeck} "
def jobStateResponse = sh(returnStdout: true, script: "curl -k ${verbose} -H Accept:application/json -H X-Rundeck-Auth-Token:${authTokenRundeck} ${jobStateUrl}")
def jobStateResponseJson = readJSON text: jobStateResponse

if (jobStateResponseJson.completed) {
if (jobStateResponseJson.executionState == "FAILED") {
currentBuild.result = "FAILURE"
echo "RunDeck Job FAILED, See: ${runDeckBaseURL}/project/${runDeckProject}/job/show/${runDeckJobId}"

break;
} else {
currentBuild.result = "SUCCESS"
echo "RunDeck Job SUCCESS, See: ${runDeckBaseURL}/project/${runDeckProject}/job/show/${runDeckJobId}"

break;
}
} else {
sleep timeout
}
retries--
}

}

}
}
}


}
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.