Skip to content

Commit

Permalink
contrib/aws: Fix cluster resource leaks when jobs get superceeded
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Zegelstein <[email protected]>
  • Loading branch information
a-szegel committed Jan 8, 2025
1 parent c8c36e4 commit 8e54c8f
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions contrib/aws/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ def get_random_string(len) {
return s
}

def get_cluster_name_prefix(build_tag) {
return sh(
script: "echo ${build_tag} | sed \"s/^jenkins-//g\" | sed \"s/ //g\"",
returnStdout: true
)
}

def get_cluster_name(build_tag, os, instance_type) {
/*
* Compose the cluster name. Pcluster requires a cluster name under 60 characters.
* cluster name cannot have ".".
* Jenkins does not allow groovy to use the replace() method
* of string. Therefore we used shell command sed to replace "." with ""
*/
build_tag = sh(
script: "echo ${build_tag} | sed \"s/^jenkins-//g\" | sed \"s/ //g\"",
returnStdout: true
)
build_tag = get_cluster_name_prefix(build_tag)

def cluster_name = sh(
script: "echo '${build_tag.take(28)}-${os.take(10)}-${instance_type.take(10)}-'${get_random_string(8)} | tr -d '.\\n'",
Expand Down Expand Up @@ -133,10 +137,6 @@ pipeline {
timeout(time: 10, unit: 'HOURS')
skipDefaultCheckout()
}
environment {
// AWS region where the cluster is created
REGION="us-west-2"
}
stages {
// Cleanup workspace before job start.
stage("Clean up workspace") {
Expand Down Expand Up @@ -241,17 +241,18 @@ pipeline {
sh 'find PortaFiducia/tests/outputs -name "*.xml" | xargs du -shc'
junit testResults: 'PortaFiducia/tests/outputs/**/*.xml', keepLongStdio: false
archiveArtifacts artifacts: 'PortaFiducia/tests/outputs/**/*.*'
}
failure {
// Try To Cleanup Resources
def regions = ["us-east-1", "eu-north-1", "us-west-2"]
cluster_name_prefix = get_cluster_name_prefix(${BUILD_TAG})
regions.each { region ->
sh ". venv/bin/activate; ./PortaFiducia/scripts/delete_manual_cluster.py --cluster-name '${cluster_name_prefix}*' --region ${region}"
}
// Windows Cluster, has a different name
sh '''
. venv/bin/activate
./PortaFiducia/scripts/delete_manual_cluster.py --cluster-name WindowsLibfabricCi_${env.CHANGE_ID}_*
'''
}
aborted {
sh '. venv/bin/activate; ./PortaFiducia/scripts/delete_manual_cluster.py --cluster-name "$BUILD_TAG"\'*\' --region $REGION'
}
// Cleanup workspace after job completes.
cleanup {
deleteDir()
}
Expand Down

0 comments on commit 8e54c8f

Please sign in to comment.