Skip to content

Instantly share code, notes, and snippets.

@ghostflare76
Last active October 7, 2022 01:12
Show Gist options
  • Save ghostflare76/c6403fa68211148eaf8b31fab5304502 to your computer and use it in GitHub Desktop.
Save ghostflare76/c6403fa68211148eaf8b31fab5304502 to your computer and use it in GitHub Desktop.
개별 배포 파이프라인에 원격 Jenkins Webhook 수행
#매개변수 JOB 구성
String Parameter
appName
fizz-download-service
String Parameter
FEATURE
fizz.v2.V2Reporter#testFileFeature
String Parameter
TAGS
@download,@thumbnail
String Parameter
ZONE
op
String Parameter : commit log 추출용도
GIT
ssh://git@git주소
#!/bin/bash
echo "==== Deployment Test ===="
curl -s -X POST -L --user id:password \
http://{karate jenkins server}/job/{jobname}/buildWithParameters \
--data zone=${ZONE} --data feature=${FEATURE} --data tags=${TAGS} --data git=${GIT}
exit $?
pipeline {
environment {
//Project Configurations
bucket = "test-report"
reportUrl = "${JOB_URL}${BUILD_ID}/cucumber-html-reports/overview-tags.html"
s3Url = "https://s3.com/${bucket}/${JOB_NAME}/${BUILD_ID}/overview-tags.html"
aws_credential = "baobab-user"
region = "default"
endpointUrl ="http://baobab.test.com"
}
//below parameters are entered in jenkins pipeline
parameters {
choice(name: 'zone', choices: ['op', 'sb', 'rc'], description: '망정보')
string(name: 'feature', defaultValue: 'fizz.v1.V1Reporter#testFileFeature')
string(name: 'tags' )
}
agent any
stages {
stage('Git Checkout') {
steps{
git branch: 'develop', credentialsId: 'cowboy76-ssh', url: 'ssh://[email protected]:7999/file_storage_service/fizz-test.git'
}
}
stage('Run Integration Tests') {
steps {
script {
if (params.tags != '') {
try {
sh "mvn clean test -U -Dtest=${params.feature} -DfailIfNoTests=false -Dkarate.env=${params.zone} -Dkarate.options='--tags ${params.tags}'"
} catch (e) {
sh "echo fail Run Integration Test"
}
} else {
try {
sh "mvn clean test -U -Dtest=${params.feature} -DfailIfNoTests=false -Dkarate.env=${params.zone}"
} catch (e) {
sh "echo fail Run Integration Test"
}
}
}
}
post {
always {
echo 'Run Integration Tests end'
}
}
}
stage('Analysis Report') {
steps {
script {
String report = readFile ("${WORKSPACE}/target/karate-reports/karate-tags.html")
String[] lines = report.split("\n")
def foundPassedLine = lines.find{ line-> line =~ /\<div id="nav-pass" class="bg-success"\>/ }
def foundFailedLine = lines.find{ line-> line =~ /\<div id="nav-fail" class="bg-danger"\>/ }
def passedMatch = (foundPassedLine =~ /[0-9]+/)
def failedMatch = (foundFailedLine =~ /[0-9]+/)
e2ePassed = passedMatch[0] as Integer
e2eFailed = failedMatch[0] as Integer
e2eTotal = e2eFailed + e2ePassed
e2ePercent = e2ePassed / e2eTotal * 100
}
}
post {
failure {
echo "Test failed"
cucumber buildStatus: 'FAIL',
jsonReportDirectory: "target/karate-reports",
failedFeaturesNumber: 1,
failedScenariosNumber: 1,
skippedStepsNumber: 1,
failedStepsNumber: 1,
fileIncludePattern: '**/*.json',
sortingMethod: 'ALPHABETICAL'
}
success {
echo "Test succeeded"
cucumber buildStatus: 'SUCCESS',
jsonReportDirectory: "target/karate-reports",
failedFeaturesNumber: 0,
failedScenariosNumber: 0,
skippedStepsNumber: 0,
failedStepsNumber: 0,
fileIncludePattern: '**/*.json',
sortingMethod: 'ALPHABETICAL'
}
}
}
stage('Upload S3') {
steps {
script {
FILES = findFiles(glob: "target/cucumber-html-reports/css/**")
withAWS(endpointUrl: "${endpointUrl}", region:"${region}", credentials:"${aws_credential}") {
FILES.each{ item ->
s3Upload(bucket:"${bucket}", path:"${JOB_NAME}/${BUILD_ID}/css/", file : "${item.path}")
}
}
FILES = findFiles(glob: "target/cucumber-html-reports/fonts/**")
withAWS(endpointUrl: "${endpointUrl}", region:"${region}", credentials:"${aws_credential}") {
FILES.each{ item ->
s3Upload(bucket:"${bucket}", path:"${JOB_NAME}/${BUILD_ID}/fonts/", file : "${item.path}")
}
}
FILES = findFiles(glob: "target/cucumber-html-reports/images/**")
withAWS(endpointUrl: "${endpointUrl}", region:"${region}", credentials:"${aws_credential}") {
FILES.each{ item ->
s3Upload(bucket:"${bucket}", path:"${JOB_NAME}/${BUILD_ID}/images/", file : "${item.path}")
}
}
FILES = findFiles(glob: "target/cucumber-html-reports/js/**")
withAWS(endpointUrl: "${endpointUrl}", region:"${region}", credentials:"${aws_credential}") {
FILES.each{ item ->
s3Upload(bucket:"${bucket}", path:"${JOB_NAME}/${BUILD_ID}/js/", file : "${item.path}")
}
}
FILES = findFiles(glob: "target/cucumber-html-reports/*.html")
withAWS(endpointUrl: "${endpointUrl}", region:"${region}", credentials:"${aws_credential}") {
FILES.each{ item ->
s3Upload(bucket:"${bucket}", path:"${JOB_NAME}/${BUILD_ID}/", file : "${item.path}")
}
}
}
}
post {
always {
echo 'Upload S3 end'
}
}
}
stage('Send Report To Teams') {
steps {
office365ConnectorSend webhookUrl: '${PTDEV_WEBHOOK_URL}',
message: 'Fizz API TEST',
factDefinitions: [[name: "Zone" , template: "${params.zone}"],
[name: "Feature", template: "${params.feature}"],
[name: "Tags", template : "${params.tags}"],
[name: "Build Number", template: "${BUILD_DISPLAY_NAME}"],
[name: "Build Time" , template: "${currentBuild.duration / 1000} (sec)"],
[name: "Test Tags", template: "Passed : ${e2ePassed} , Failed : ${e2eFailed}, Percent Passed : ${e2ePercent}%"],
[name: "Go Test Tags Result", template: "${s3Url}"]]
}
}
}
post {
always {
cleanWs()
dir("${env.WORKSPACE}@tmp") {
deleteDir()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment