As developers, we want to streamline and take as much human interaction out of the deployment process. This is where Continuous Integration comes in. At Rapid Development, we use Jenkins as our open source solution for handling all the details and process surrounding the deployment of a site.
I have recently written about hosting a static site on s3 and securing it with a certificate. The last part then is pushing code.
In Jenkins, ensure that the Jenkins Pipeline Deployment plugin is enabled.
Then, in the root of your project, create a Jenkinsfile. Here is an example of what that jenkinsfile should look like.
pipeline {
agent any
stages {
stage('Deploy to s3') {
when {
branch 'master'
}
steps {
slackSend channel: "#<channel>", message: "Deployment Starting: ${env.JOB_NAME}, build number ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
echo 'Deploying to RDG AWS s3 bucket.'
withAWS(region:'<AWS Region: like us-east-1>', credentials:'RDG AWS') {
s3Delete(bucket: '<Bucket Name>', path:'**/*')
s3Upload(bucket: '<Bucket Name>', includePathPattern:'**/*')
}
}
}
}
post {
success {
slackSend channel: "#<channel>", color: "good", message: "Deployment Complete: ${env.JOB_NAME}, build number ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
}
failure {
slackSend channel: "#<channel>", color: "danger", message: "Deployment Failed: ${env.JOB_NAME}, build number ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
}
// always {
// slackSend ...
// }
}
}