87 lines
2.7 KiB
Groovy
87 lines
2.7 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
DB_NAME = 'url_shortener.db'
|
|
ZIP_FILE = ''
|
|
}
|
|
stages {
|
|
stage('Init') {
|
|
steps {
|
|
sh 'rbenv local 3.2.2'
|
|
sh 'echo "ENV[\\\"APP_SESSION_SECRET\\\"] ||= $(ruby secret.rb)" > .env.rb'
|
|
sh 'echo "ENV[\\\"DB_NAME\\\"] ||= \\\"${DB_NAME}\\\"" >> .env.rb'
|
|
sh 'cat .env.rb'
|
|
}
|
|
}
|
|
stage('Build dependencies') {
|
|
steps {
|
|
sh 'bundle install'
|
|
sh 'sequel -m db/migrations sqlite://db/${DB_NAME}'
|
|
}
|
|
}
|
|
stage('Run tests') {
|
|
steps {
|
|
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
|
|
sh 'cucumber features --format html --out cucumber.html'
|
|
}
|
|
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
|
|
sh 'rspec spec --format html --out spec.html'
|
|
}
|
|
}
|
|
}
|
|
stage('Report results') {
|
|
steps {
|
|
publishHTML (target: [
|
|
allowMissing: false,
|
|
alwaysLinkToLastBuild: false,
|
|
keepAll: true,
|
|
reportDir: '.',
|
|
reportFiles: 'cucumber.html, spec.html, coverage/index.html',
|
|
reportName: 'Test Results',
|
|
reportTitles: 'Cucumber Results, RSpec Results, Test Coverage'])
|
|
}
|
|
}
|
|
stage('Build production deliverable') {
|
|
steps {
|
|
script {
|
|
env.ZIP_FILE="url-shortener_$(date "+%Y-%m-%d_%H-%M-%S").tgz"
|
|
}
|
|
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
|
sh ''' #!/usr/local/bin/bash
|
|
CUR_DIR=$(pwd)
|
|
mkdir -p /tmp/url-shortener
|
|
cp -R * /tmp/url-shortener
|
|
cd /tmp/url-shortener
|
|
rm -rf features spec coverage db/*.db .git* Jenkinsfile *.html
|
|
cd /tmp
|
|
tar -czvf $ZIP_FILE url-shortener/
|
|
mv /tmp/$ZIP_FILE $CUR_DIR/
|
|
'''
|
|
}
|
|
archiveArtifacts artifacts: '*.tgz'
|
|
}
|
|
}
|
|
stage('Clean up deliverable') {
|
|
steps {
|
|
sh 'rm -rf /tmp/url-shortener'
|
|
sh 'rm -rf $ZIP_FILE'
|
|
}
|
|
}
|
|
}
|
|
post {
|
|
success {
|
|
mattermostSend channel: 'git-messages', color: 'good', message: "[${JOB_NAME}](${JOB_URL}) [#${BUILD_NUMBER}](${BUILD_URL}) ([Gitea](${GIT_URL}))", text: 'Build Finished Successfully'
|
|
}
|
|
unstable {
|
|
mattermostSend channel: 'git-messages', color: 'warning', message: "[${JOB_NAME}](${JOB_URL}) [#${BUILD_NUMBER}](${BUILD_URL}) ([Gitea](${GIT_URL}))", text: "Build Unstable"
|
|
}
|
|
failure {
|
|
mattermostSend channel: 'git-messages', color: 'danger', message: "[${JOB_NAME}](${JOB_URL}) [#${BUILD_NUMBER}](${BUILD_URL}) ([Gitea](${GIT_URL}))", text: "Build Failed"
|
|
}
|
|
always {
|
|
cleanWs deleteDirs: true, patterns: [[pattern: '*', type: 'INCLUDE']]
|
|
}
|
|
}
|
|
}
|