| |
@@ -1,3 +1,4 @@
|
| |
+ import java.text.*
|
| |
pipeline {
|
| |
agent {
|
| |
kubernetes {
|
| |
@@ -48,6 +49,35 @@
|
| |
])
|
| |
}
|
| |
}
|
| |
+ stage('Cleanup') {
|
| |
+ // Cleanup all test environments that were created 1 hour ago in case of failures of previous cleanups.
|
| |
+ steps {
|
| |
+ script {
|
| |
+ openshift.withCluster() {
|
| |
+ def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
| |
+ df.setTimeZone(TimeZone.getTimeZone('UTC'))
|
| |
+ // Get all OpenShift objects of previous test environments
|
| |
+ def oldObjs = openshift.selector('dc,deploy,configmap,secret,svc,route',
|
| |
+ ['template': 'waiverdb-test', 'app':'waiverdb'])
|
| |
+ def now = new Date()
|
| |
+ // Delete all objects that are older than 1 hour
|
| |
+ for (objName in oldObjs.names()) {
|
| |
+ def obj = openshift.selector(objName)
|
| |
+ def objData = obj.object()
|
| |
+ if (!objData.metadata.creationTimestamp)
|
| |
+ continue
|
| |
+ def creationTime = df.parse(objData.metadata.creationTimestamp)
|
| |
+ // 1 hour = 1000 * 60 * 60 ms
|
| |
+ if (now.getTime() - creationTime.getTime() < 1000 * 60 * 60)
|
| |
+ continue
|
| |
+ echo "Deleting ${objName}..."
|
| |
+ obj.delete()
|
| |
+ echo "Deleted ${objName}"
|
| |
+ }
|
| |
+ }
|
| |
+ }
|
| |
+ }
|
| |
+ }
|
| |
stage('Run functional tests') {
|
| |
environment {
|
| |
// Jenkins BUILD_TAG could be too long (> 63 characters) for OpenShift to consume
|
| |
Fix https://pagure.io/waiverdb/issue/248
This PR will cleanup all test environments that were created 1 hour ago
before creating a new test environment.
The following Java methods must be approved to allow the pipeline script
to access the Java DateTime API. For more information about Jenkins
In-process Script Approval, see
https://jenkins.io/doc/book/managing/script-approval/.