String QA_ACCOUNT_ID = '437795906767'
String QA_BUCKET_NAME = 'qa-publishing-compositions'
String PROD_BUCKET_NAME = 'prod-publishing-compositions'
String SESSION_NAME = 'qa-publishing-s3-cleanup-job'
String CLEANUP_ROLE = 'qa-publishing-s3-cleanup-role'

pipeline {
    agent any

    parameters {
        string(name: 'SHARED_LIBRARIES_VERSION', defaultValue: 'master', description: 'Shared Libraries Version')
    }

    stages {    
        stage('Load Shared Libraries') {
            steps {
                library "jenkins-global-libraries@${params.SHARED_LIBRARIES_VERSION}"
            }
        }

        stage('Cleanup QA S3 Bucket') {
            steps {
                withAWS(role: CLEANUP_ROLE, roleAccount: QA_ACCOUNT_ID, roleSessionName: SESSION_NAME, useNode: true) {
                    s3Delete(bucket: QA_BUCKET_NAME, path: 'changelog-reports/')
                }
            }
        }

        stage('Copy reports templates') {
            steps {
                withAWS(role: CLEANUP_ROLE, roleAccount: QA_ACCOUNT_ID, roleSessionName: SESSION_NAME, useNode: true) {
                    s3Copy(fromBucket: PROD_BUCKET_NAME, fromPath: 'changelog-reports/changelog_report_adhoc_template.xlsx', toBucket: QA_BUCKET_NAME, toPath: 'changelog-reports/changelog_report_adhoc_template.xlsx')
                    s3Copy(fromBucket: PROD_BUCKET_NAME, fromPath: 'changelog-reports/changelog_report_new_delivery_template.xlsx', toBucket: QA_BUCKET_NAME, toPath: 'changelog-reports/changelog_report_new_delivery_template.xlsx')
                    s3Copy(fromBucket: PROD_BUCKET_NAME, fromPath: 'changelog-reports/changelog_report_update_delivery_template.xlsx', toBucket: QA_BUCKET_NAME, toPath: 'changelog-reports/changelog_report_update_delivery_template.xlsx')
                    s3Copy(fromBucket: PROD_BUCKET_NAME, fromPath: 'changelog-reports/changelog_report_smp_update_delivery_template.xlsx', toBucket: QA_BUCKET_NAME, toPath: 'changelog-reports/changelog_report_smp_update_delivery_template.xlsx')
                    s3Copy(fromBucket: PROD_BUCKET_NAME, fromPath: 'changelog-reports/failed_compositions_template.xlsx', toBucket: QA_BUCKET_NAME, toPath: 'changelog-reports/failed_compositions_template.xlsx')
                }
            }
        }
    }
}