How to deploy to AWS S3 from Jenkinsfile with Docker Containers as slave

Here’s Jenkinsfile with sample code:
node(‘docker-awscli-slave’) {
stage ‘Deploy to Stage’
withCredentials([usernamePassword(credentialsId: ‘xxxxxxxxxxxx’, passwordVariable: ‘AWSSECRET’, usernameVariable: ‘AWSACCESSKEY’)]) {
try{
git credentialsId: ‘xxxxxxxxxxxxxxx’, url: ‘https://github.com/repo/aws-s3-poc.git’
sh ‘aws configure set aws_access_key_id $AWSACCESSKEY’
sh ‘aws configure set aws_secret_access_key $AWSSECRET’
sh ‘aws configure set default.s3.signature_version s3v4’
sh ‘aws configure set default.region us-east-2’
sh ‘aws s3 sync ./static/ s3://project/folder/ –region us-east-2’
notify(‘Success -Need Approval for production deploy’)
}
catch (err) {
notify(“Failed ${err}”)
currentBuild.result = ‘FAILURE’
}
}
}
}

notify(‘success deploy to production’)
}
catch (err) {
notify(“Failed ${err}”)
currentBuild.result = ‘FAILURE’
}
}
}

}

def notify(status){
emailext (
to: “saurabhahujaxx@gmail.com”,
subject: “‘${env.BUILD_TAG} – Status – ${status}!'”,
attachLog: true,
body: “”” JOB FAILED “”” )
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s