DBZ-5094 Add cleanup job and ansible script

This commit is contained in:
Jiri Novotny 2022-05-10 14:40:34 +02:00 committed by Jakub Cechacek
parent 035d6b4c14
commit eaa112f073
4 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,23 @@
pipelineJob('node-snapshot-history-cleanup') {
displayName('Jenkins node snapshot history cleanup')
description('Delete old snapshots from openstack')
logRotator {
numToKeep(10)
}
parameters {
stringParam('DBZ_GIT_REPOSITORY', 'https://github.com/debezium/debezium', 'Debezium repository where the ansible script is located')
stringParam('DBZ_GIT_BRANCH', '*/main', 'A branch/tag where the ansible script is located')
stringParam('SNAPSHOT_NAME', 'debezium-jenkins-node-centos8', 'Name of the snapshot')
stringParam('OPENSTACK_AUTH', 'psi-clouds-yaml', 'yaml with openstack authentication')
stringParam('CLOUD_NAME', 'openstack', 'Name of openstack cloud')
}
definition {
cps {
script(readFileFromWorkspace('jenkins-jobs/pipelines/node_snapshot_history_cleanup_pipeline.groovy'))
sandbox()
}
}
}

View File

@ -4,6 +4,7 @@ listView('Jenkins') {
name('job-configurator')
name('MonitoringTest')
name('node-snapshot-build')
name('node-snapshot-history-cleanup')
}
columns {
status()

View File

@ -0,0 +1,48 @@
pipeline {
agent {
label 'Core'
}
stages {
stage('CleanWorkspace') {
steps {
cleanWs()
}
}
stage('Checkout') {
steps {
checkout([
$class : 'GitSCM',
branches : [[name: "${DBZ_GIT_BRANCH}"]],
userRemoteConfigs: [[url: "${DBZ_GIT_REPOSITORY}"]],
extensions : [[$class : 'RelativeTargetDirectory',
relativeTargetDir: 'debezium']],
])
}
}
stage('Delete old snapshots') {
steps {
withCredentials([
file(credentialsId: "$OPENSTACK_AUTH", variable: 'OS_AUTH')
]) {
sh '''
cp ${OS_AUTH} ./clouds.yaml
cp ${WORKSPACE}/debezium/jenkins-jobs/scripts/cleanup_images_ansible.yml ./cleanup_images_ansible.yml
ansible-galaxy collection install openstack.cloud
ansible-playbook cleanup_images_ansible.yml --extra-vars "cloud_name="${CLOUD_NAME}" snapshot_name="${SNAPSHOT_NAME}""
'''
}
}
}
}
post {
always {
mail to: 'debezium-qe@redhat.com', subject: "Jenkins node image snapshot history cleanup #${BUILD_NUMBER} finished", body: """
${currentBuild.projectName} run ${BUILD_URL} finished with result: ${currentBuild.currentResult}
"""
}
}
}

View File

@ -0,0 +1,31 @@
---
- name: Get Image
hosts: localhost
gather_facts: no
environment:
connection: local
tasks:
- name: Collect image facts
os_image_facts:
cloud: openstack
delegate_to: localhost
- name: Find images
set_fact:
image: "{{ ( openstack_image | selectattr('name', 'match', '(?i)^' + snapshot_name + '-[0-9]{4}-[0-9]{2}-[0-9]{2}') | map(attribute='name')) | list }}"
run_once: true
- name: Delete old snapshot
openstack.cloud.image:
cloud: "openstack"
name: "{{ item }}"
state: absent
register: deleted
until: deleted is not failed
retries: 5
delay: 60
with_items: "{{ image }}"