From 37bb917fde10c70a249711a37caa5149a0ea90e7 Mon Sep 17 00:00:00 2001 From: Anh Hoang Nguyen Date: Mon, 18 Sep 2023 14:26:47 -0400 Subject: [PATCH] Add pipeline.groovy --- pipeline.groovy | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 4 +-- 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 pipeline.groovy diff --git a/pipeline.groovy b/pipeline.groovy new file mode 100644 index 0000000..7602911 --- /dev/null +++ b/pipeline.groovy @@ -0,0 +1,83 @@ +pipeline { + agent any + environment { + CLONE_STAGE_STATUS = "FAIL" + PYLINT_STAGE_STATUS = "FAIL" + GENERATE_BUILD_INFORMATION_STAGE_STATUS = "FAIL" + BUILD_STAGE_STATUS = "FAIL" + UNIT_TEST_STAGE_STATUS = "FAIL" + PYPI_STAGE_STATUS = "FAIL" + AUTO_DOC_STAGE_STATUS = "FAIL" + MAINTAINERS = "anhhoang.nguyen@concordia.ca" + } + + stages { + stage('Clone') { + steps { + script { + catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { + echo 'Start branch development pipeline' + dir('webhook-test') { + git branch: 'main', changelog: false, credentialsId: 'Terence', poll: false, url: 'https://nextgenerations-cities.encs.concordia.ca/gitea/a_nguyen/webhook-test.git' + } + CLONE_STAGE_STATUS = "SUCCESS" + } + } + } + } + stage('Webhook Handler') { + steps { + script { + // Get the raw JSON content from the REQUEST_CONTENT environment variable + // def rawPayload = env.REQUEST_CONTENT + + // Parse the JSON content using jsonSlurper + def jsonSlurper = new groovy.json.JsonSlurper() + def jsonPayload = jsonSlurper.parseText(payload) + + echo jsonPayload.sender.login + " " + jsonPayload.sender.email + " " + jsonPayload.sender.name + } + } + } + + stage('Get/Set Build Information') { + steps { + sh 'rm -r webhook-test/.jenkins || echo "Creating runtime .jenkins folder. Will be removed in cleanup stage." && mkdir -p webhook-test/.jenkins' + + sh 'cd webhook-test && git log -1 --pretty=format:\'%an\' > .jenkins/git_author && git log -1 --pretty=format:\'%ae\' > .jenkins/git_author_email && git log -1 --pretty=format:\'%h\' > .jenkins/git_hash' + + script { + GENERATE_BUILD_INFORMATION_STAGE_STATUS="SUCCESS" + } + } + } + stage('Cleanup') { + steps { + script { + git_author = readFile('webhook-test/.jenkins/git_author').trim() + git_author_email = readFile('webhook-test/.jenkins/git_author_email').trim() + git_hash = readFile('webhook-test/.jenkins/git_hash').trim() + } + mail to: "13dd15fb.liveconcordia.onmicrosoft.com@ca.teams.ms", + subject: "${env.BUILD_TAG} Pipeline Results", + body: """ +Results of Hub/release Pipeline ${env.BUILD_TAG} + +Build triggered by: "${jsonPayload.sender.name} - ${jsonPayload.sender.login}" +Commit hash: "${jsonPayload.after}" +See changes: "${jsonPayload.compare_url}" +Email: "${jsonPayload.sender.email}" + +Clone Stage: ${CLONE_STAGE_STATUS} +Generate Build Information Stage: ${GENERATE_BUILD_INFORMATION_STAGE_STATUS} +Build Stage : ${BUILD_STAGE_STATUS} +Unit Test Stage: ${UNIT_TEST_STAGE_STATUS} + +To access the pipeline run logs, please go here: http://nextgenerations-cities.encs.concordia.ca:8080/job/Hub/job/release/ + """ + sh 'rm -rf webhook-test/.jenkins' + cleanWs() + } + } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index f24c318..5dd98b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,8 +29,8 @@ mod tests { #[test] fn test_user_age() { - let user = User::new("Test User", 2000); + let user = User::new("Test User", 1999); let age = user.age(); - assert_eq!(age, 23); // Adjust the expected age based on the current year + assert_eq!(age, 24); // Adjust the expected age based on the current year } }