pipeline {
agent any
stages {
stage('Preparation') {
steps {
git branch: '**',
credentialsId: '95ba7d88-78e8-429d-8d3a-bb51a6800c37',
url: '[email protected]:harukaedudev/ahmeng.git'
}
}
stage("Run Dockerize Database") {
steps {
sh """
docker run --name ahmeng_test --hostname=ahmeng_test -e MYSQL_USER=deploy -e MYSQL_PASSWORD=deployer -e MYSQL_ROOT_PASSWORD=deployer -e MYSQL_DATABASE=ahmeng_test -d mysql:5.7
sleep 30
"""
}
}
stage('Copy ENV File') {
steps {
sh """
cp ${JENKINS_HOME}/env/ahmeng/config/* ${WORKSPACE}/config/
"""
}
}
stage("Setup Database") {
steps {
sh """source ~/.bashrc
export RAILS_ENV=test
DBTEST=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' ahmeng_test`
sed "s|10.10.2.83|\"\$DBTEST\"|g" -i \${WORKSPACE}/config/application.yml
sleep 10
bundle exec rake db:setup
bundle exec rake db:test:prepare
"""
}
}
stage("Install Dependencies") {
steps {
sh """source ~/.bashrc
bundle install --deployment --path vendor/bundle
"""
}
}
stage("Testing") {
steps {
sh """source ~/.bashrc
bundle exec rake spec
bundle exec brakeman
bundle exec rubocop
"""
}
}
}
post {
always {
sh """
docker stop ahmeng_test
docker rm ahmeng_test
"""
}
success {
sh """source ${JENKINS_HOME}/.bashrc
bundle exec cap develop deploy
BUILD_NOTIF=\$(echo -e "BUILD : ${BUILD_NUMBER}\nJOB : AHMENG\nBUILD STATUS : SUCCESS\nDEPLOY STATUS : DEPLOYED\nURL : ${BUILD_URL}")
/usr/local/bin/telegram-send "\$BUILD_NOTIF"
"""
}
failure {
sh """
BUILD_NOTIF=\$(echo -e "BUILD : ${BUILD_NUMBER}\nJOB : AHMENG\nBUILD STATUS : FAILED\nURL : ${BUILD_URL}")
/usr/local/bin/telegram-send "\$BUILD_NOTIF"
"""
}
unstable {
sh """
BUILD_NOTIF=\$(echo -e "BUILD : ${BUILD_NUMBER}\nJOB : AHMENG\nBUILD STATUS : UNSTABLE\nURL : ${BUILD_URL}")
/usr/local/bin/telegram-send "\$BUILD_NOTIF"
"""
}
}
}
Last active
September 17, 2019 02:25
-
-
Save philiplambok/feb2aac5705348a993d3bece975b9dd2 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment