Skip to content

Commit

Permalink
Create Jenkinsfile.metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceKropp-Raytheon authored Dec 2, 2024
1 parent cabf94b commit 5874b4f
Showing 1 changed file with 164 additions and 0 deletions.
164 changes: 164 additions & 0 deletions .cicd/Jenkinsfile.metrics
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
matchedNode = []
generateBaselineNode = []
for (label in pullRequest.labels) {
listOfLabelNodeNames = jenkins.model.Jenkins.instance.nodes.collect {
node -> node.getLabelString().contains(label) ? node.name : null

if ((label.matches(node.getLabelString()+"-(.*)"))) {
matchedNode += node.getLabelString()
}

if ((label.matches(node.getLabelString()+"(.*)-BL"))) {
generateBaselineNode += node.getLabelString()
}
}
}

modifiedLabels = matchedNode.collect{"'" + it + "'"}
baselineLabels = generateBaselineNode.collect{"'" + it + "'"}
def generateStage(nodeLabel) {
return {
stage("Running on ${nodeLabel}") {
node(nodeLabel) {
cleanWs()
checkout scm
script {
try {
echo "Running on ${nodeLabel}"
if (baselineLabels.contains(nodeLabel)) {
sh '''

git config user.email "[email protected]"
git config user.name "epic-cicd-jenkins"
echo "Testing concluded...removing labels for $machine from $GIT_URL"

export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1
git add logs/RegressionTests_$machine_name_logs.log
git commit -m "[AutoRT] $machine Job Completed.\n\n\n on-behalf-of @ufs-community <[email protected]>"
git pull sshorigin $FORK_BRANCH
git push sshorigin HEAD:$FORK_BRANCH

tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log

GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)

curl --silent -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" https://api.github.com/repos/${GIT_OWNER}/${GIT_REPO_NAME}/issues/${CHANGE_ID}/labels/$machine-BL
'''
s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'noaa-epic-prod-jenkins-artifacts', excludedFile: '', flatten: true, gzipFiles: false, keepForever: false, managedArtifacts: true, noUploadOnFailure: false, selectedRegion: 'us-east-1', showDirectlyInBrowser: false, sourceFile: "**/*tgz*", storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'main', userMetadata: []

}
else {
sh '''

git config user.email "[email protected]"
git config user.name "epic-cicd-jenkins"
echo "Testing concluded...removing labels for $machine from $GIT_URL"

export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1
git add logs/RegressionTests_$machine_name_logs.log
git commit -m "[AutoRT] $machine Job Completed.\n\n\n on-behalf-of @ufs-community <[email protected]>"
git pull sshorigin $FORK_BRANCH
git push sshorigin HEAD:$FORK_BRANCH

tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log

GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)

curl --silent -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" https://api.github.com/repos/${GIT_OWNER}/${GIT_REPO_NAME}/issues/${CHANGE_ID}/labels/$machine-BL
'''
s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'noaa-epic-prod-jenkins-artifacts', excludedFile: '', flatten: true, gzipFiles: false, keepForever: false, managedArtifacts: true, noUploadOnFailure: false, selectedRegion: 'us-east-1', showDirectlyInBrowser: false, sourceFile: "**/*tgz*", storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'main', userMetadata: []
}
}
catch(err) {
sh '''
export machine=${NODE_NAME}
export CHANGE_ID=${CHANGE_ID}
export SSH_ORIGIN=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.repo.ssh_url')
export FORK_BRANCH=$(curl --silent https://api.github.com/repos/ufs-community/ufs-weather-model/pulls/$CHANGE_ID | jq -r '.head.ref')
cd $WORKSPACE/tests
git config user.email "[email protected]"
git config user.name "epic-cicd-jenkins"
export machine_name_logs=$(echo $machine | awk '{ print tolower($1) }')
echo "Testing concluded...removing labels for $machine from $GIT_URL"
git remote -v | grep -w sshorigin > /dev/null 2>&1 && git remote remove sshorigin > /dev/null 2>&1
git remote add sshorigin $SSH_ORIGIN > /dev/null 2>&1

tar --create --gzip --verbose --dereference --file "${machine_name_logs}.tgz" ${WORKSPACE}/tests/logs/*.log

GIT_OWNER=$(echo $GIT_URL | cut -d '/' -f4)
GIT_REPO_NAME=$(echo $GIT_URL | cut -d '/' -f5 | cut -d '.' -f1)

curl --silent -X DELETE -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" https://api.github.com/repos/${GIT_OWNER}/${GIT_REPO_NAME}/issues/${CHANGE_ID}/labels/{$machine-RT,$machine-BL}
'''
s3Upload consoleLogLevel: 'INFO', dontSetBuildResultOnFailure: false, dontWaitForConcurrentBuildCompletion: false, entries: [[bucket: 'noaa-epic-prod-jenkins-artifacts', excludedFile: '', flatten: true, gzipFiles: false, keepForever: false, managedArtifacts: true, noUploadOnFailure: false, selectedRegion: 'us-east-1', showDirectlyInBrowser: false, sourceFile: "**/*tgz*", storageClass: 'STANDARD', uploadFromSlave: false, useServerSideEncryption: false]], pluginFailureResultConstraint: 'FAILURE', profileName: 'main', userMetadata: []
currentBuild.result = 'FAILURE'
}
}
}
}
}
}

def parallelStagesMap = modifiedLabels.collectEntries {
["${it}" : generateStage(it)]
}

pipeline {
agent none
environment {
ACCNR = 'epic'
AWS_PROD_ACCOUNT_ID = credentials('AWS_PROD_ACCOUNT_ID')
AWS_PROD_SNS_TOPIC = credentials('AWS_PROD_SNS_TOPIC')
GITHUB_TOKEN = credentials('GithubJenkinsNew')
GIT_URL = 'https://github.com/ufs-community/ufs-weather-model.git'
}
stages {
stage('Launch SonarQube') {
steps {
script {
echo "BRANCH_NAME=${env.CHANGE_BRANCH}"
echo "FORK_NAME=${env.CHANGE_FORK}"
echo "CHANGE_URL=${env.CHANGE_URL}"
echo "CHANGE_ID=${env.CHANGE_ID}"
build job: '/ufs-weather-model/ufs-wm-sonarqube', parameters: [
string(name: 'BRANCH_NAME', value: env.CHANGE_BRANCH ?: 'develop'),
string(name: 'FORK_NAME', value: env.CHANGE_FORK ?: ''),
string(name: 'CHANGE_URL', value: env.CHANGE_URL ?: ''),
string(name: 'CHANGE_ID', value: env.CHANGE_ID ?: '')
], wait: false
}
}
}
stage('Run Regression Tests in Parallel') {
steps {
script {
parallel parallelStagesMap
}
}
}
}
post {
success {
node('built-in') {
echo 'This will run only if successful.'
sh '''
aws sns publish --topic-arn "arn:aws:sns:us-east-1:${AWS_PROD_ACCOUNT_ID}:${AWS_PROD_SNS_TOPIC}" --region us-east-1 --message '{"version":"1.0","source":"custom","content":{"description":":sunny: Jenkins build *'"$JOB_NAME"' '"$BUILD_NUMBER"'* with *PR-'"$CHANGE_ID"'* *succeeded*"}}'
'''
}
}
failure {
node('built-in') {
echo 'This will run only if the run was marked as unstable.'
sh '''
aws sns publish --topic-arn "arn:aws:sns:us-east-1:${AWS_PROD_ACCOUNT_ID}:${AWS_PROD_SNS_TOPIC}" --region us-east-1 --message '{"version":"1.0","source":"custom","content":{"description":":warning: Jenkins build *'"$JOB_NAME"' '"$BUILD_NUMBER"'* with *PR-'"$CHANGE_ID"'* *failed!*"}}'
'''
}
}
}
}

0 comments on commit 5874b4f

Please sign in to comment.