Export logs to S3 when running gatling-gerrit-test

When running gatling tests against gerrit it is useful to make the logs
of the execution available to Jenkins so that further investigations and
analysis can be performed in case of regressions or failures.

Add an additional stage in which logs are exported from CloudWatch to S3
by running the aws-gerrit command `export-logs`.

The output of the publicly available logs will be outputted in the
console so that it can be retrieved if needed.

Bug: Issue 14450
Change-Id: Iae0d8035d8fcc2845a75a0fd7c524d04ec2a9d01
diff --git a/jenkins-docker/slave-aws/Dockerfile b/jenkins-docker/slave-aws/Dockerfile
index 2a2c04d..b72e8dc 100644
--- a/jenkins-docker/slave-aws/Dockerfile
+++ b/jenkins-docker/slave-aws/Dockerfile
@@ -9,4 +9,4 @@
       $(lsb_release -cs) \
       stable" && \
     apt-get update && \
-    apt-get install -y docker-ce-cli
+    apt-get install -y docker-ce-cli jq
diff --git a/jenkins/gatling-test-pipeline.groovy b/jenkins/gatling-test-pipeline.groovy
index 390e333..faa09c3 100644
--- a/jenkins/gatling-test-pipeline.groovy
+++ b/jenkins/gatling-test-pipeline.groovy
@@ -32,6 +32,8 @@
             string(name: 'GIT_HTTP_USERNAME', defaultValue: '', description: 'Username for Git/HTTP testing, use vault by default')
             password(name: 'GIT_HTTP_PASSWORD', defaultValue: '', description: 'Password for Git/HTTP testing, use vault by default')
 
+            string(name: 'S3_EXPORT_LOGS_BUCKET_NAME', defaultValue: 'gerritforge-export-logs', description: 'S3 bucket to export logs to')
+
             string(name: 'GERRIT_PROJECT', defaultValue: 'load-test', description: 'Gerrit project for load test')
             string(name: 'NUM_USERS', defaultValue: '10', description: 'Number of concurrent user sessions')
             string(name: 'DURATION', defaultValue: '2 minutes', description: 'Total duration of the test')
@@ -173,7 +175,17 @@
                     }
                 }
             }
-
+            stage("Export Cloudwatch logs to S3") {
+                steps {
+                    withCredentials([usernamePassword(usernameVariable: "AWS_ACCESS_KEY_ID",
+                            passwordVariable: "AWS_SECRET_ACCESS_KEY",
+                            credentialsId: "aws-credentials-id")]) {
+                        dir ('aws-gerrit/single-primary') {
+                            sh "make AWS_REGION=${params.AWS_REGION} AWS_PREFIX=${params.AWS_PREFIX} EXPORT_FROM_MILLIS=${epochTime} S3_EXPORT_LOGS_BUCKET_NAME=${params.S3_EXPORT_LOGS_BUCKET_NAME} export-logs"
+                        }
+                    }
+                }
+            }
         }
         post {
             cleanup {