82 lines
2.6 KiB
Groovy
82 lines
2.6 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
APP_SESSION_SECRET = ''
|
|
DB_NAME = 'url_shortener.db'
|
|
}
|
|
stages {
|
|
stage('Init') {
|
|
steps {
|
|
sh 'rbenv local 3.2.2'
|
|
script {
|
|
env.APP_SESSION_SECRET = sh(script: 'ruby secret.rb', returnStdout: true)
|
|
}
|
|
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 deliverable') {
|
|
steps {
|
|
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
|
|
sh 'mkdir -p url-shortener'
|
|
sh 'echo $SHELL'
|
|
sh 'shopt -s extglob'
|
|
sh 'cp -R !(url-shortener) url-shortener/'
|
|
sh 'rm -rf url-shortener/features'
|
|
sh 'rm -rf url-shortener/spec'
|
|
sh 'rm -rf url-shortener/coverage'
|
|
sh 'tar -czvf url-shortener.tgz url-shortener/'
|
|
archiveArtifacts artifacts: 'url-shortener.tgz'
|
|
}
|
|
}
|
|
}
|
|
stage('Clean up deliverable') {
|
|
steps {
|
|
sh 'rm -rf url-shortener'
|
|
sh 'rm -rf url-shortener.tgz'
|
|
}
|
|
}
|
|
}
|
|
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"
|
|
}
|
|
}
|
|
}
|