pipeline {
agent any
stages {
stage('Setting up environment variables'){
def AWS_ACCOUNT_ID = '01010101010101010'
def REGION = 'eu-north-1'
def ROLE = 'MyIamRole'
def EXTERNAL_ID = 'MyExternalId'
def BUCKET = 'my-artifacts'
def PROJECT = 'my-project'
}
stage ('Build app and upload artifacts to S3'){
agent {
label 'my-slave-with-maven'
}
steps {
// build source code
dir('./SourceCode') {
sh 'mvn -B clean package'
}
}
script {
// upload files to S3
def jar_files = findFiles(glob: "**/SourceCode/${PROJECT}/target/*.jar")
jar_files.each {
echo "JAR found: ${it}"
withAWS(externalId: "${EXTERNAL_ID}", region: "${REGION}", role: "${ROLE}", roleAccount: "${AWS_ACCOUNT_ID}") {
s3Upload(file: "${it}", bucket: "${BUCKET}", path: "${PROJECT}/", acl: 'BucketOwnerFullControl')
}
}
}
}
}
}
}