Compare commits

...

10 Commits

Author SHA1 Message Date
bucky b62d45d0d8 Merge pull request 'prod-artifact-when-good' (#34) from prod-artifact-when-good into master
Gitea Bucky/url-shortener/pipeline/head This commit looks good Details
Reviewed-on: #34
2023-10-23 15:54:27 -07:00
Adam Townsend 0dc792b0bf added try catch wrappers around other parts. if they fail, don't build
Gitea Bucky/url-shortener/pipeline/head This commit looks good Details
the deliverable
2023-10-23 15:48:42 -07:00
Adam Townsend 5f4209dbe8 testing skipping building the artifact at the end (and cleanup of it)
Gitea Bucky/url-shortener/pipeline/head This commit looks good Details
2023-10-23 15:10:16 -07:00
Adam Townsend fbba67a9bd install, not clean, since it changed the bundle location
Gitea Bucky/url-shortener/pipeline/head This commit looks good Details
2023-10-23 15:05:20 -07:00
Adam Townsend 5cd296cb70 when is outside the steps
Gitea Bucky/url-shortener/pipeline/head There was a failure building this commit Details
2023-10-23 15:03:45 -07:00
Adam Townsend 7c0f6eb603 limit building deployment artifact
Gitea Bucky/url-shortener/pipeline/head There was a failure building this commit Details
+ added buildArtifact variable and set it to true
+ in auditing stage, if there's an error, set buildArtifact to false
+ in build artifact stage, if buildArtifact is true, build  it
2023-10-23 14:58:02 -07:00
Adam Townsend de3dcc48ab removed the when, and removed unnecessary rm command
Gitea Bucky/url-shortener/pipeline/head There was a failure building this commit Details
2023-10-23 12:31:29 -07:00
Adam Townsend 958091e000 see if we can access the buildResult status to use it 2023-10-23 11:32:02 -07:00
Adam Townsend 35583e404e move the local path in the build prod artifact stage to make the tests
quicker
2023-10-23 07:43:30 -07:00
Adam Townsend 0e9342fab6 only build the production environment when the previous steps all executed successfully 2023-10-23 07:41:52 -07:00
1 changed files with 51 additions and 8 deletions

59
Jenkinsfile vendored
View File

@ -1,3 +1,5 @@
def buildArtifact = true
pipeline { pipeline {
agent { label 'ruby && freebsd' } agent { label 'ruby && freebsd' }
@ -18,7 +20,6 @@ pipeline {
} }
stage('Build dependencies') { stage('Build dependencies') {
steps { steps {
sh 'bundle config set --local path "vendor"'
sh 'bundle install' sh 'bundle install'
sh 'sequel -m db/migrations sqlite://db/${DB_NAME}' sh 'sequel -m db/migrations sqlite://db/${DB_NAME}'
} }
@ -26,25 +27,57 @@ pipeline {
stage('Audit Dependencies') { stage('Audit Dependencies') {
steps { steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh 'bundle exec ruby-audit check' script {
sh 'bundle exec bundle-audit check >> audit.html' try {
sh 'bundle exec ruby-audit check'
sh 'bundle exec bundle-audit check >> audit.html'
} catch (e) {
script {
buildArtifact = false
}
}
}
} }
} }
} }
stage('Code Linting') { stage('Code Linting') {
steps { steps {
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh 'bundle exec rubocop --format html --out rubocop.html' script {
try {
sh 'bundle exec rubocop --format html --out rubocop.html'
} catch (e) {
script {
buildArtifact = false
}
}
}
} }
} }
} }
stage('Run tests') { stage('Run tests') {
steps { steps {
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh 'bundle exec cucumber features --format html --out cucumber.html' script {
try {
sh 'bundle exec cucumber features --format html --out cucumber.html'
} catch (e) {
script {
buildArtifact = false
}
}
}
} }
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh 'bundle exec rspec spec --format html --out spec.html' script {
try {
sh 'bundle exec rspec spec --format html --out spec.html'
} catch (e) {
script {
buildArtifact = false
}
}
}
} }
} }
} }
@ -61,13 +94,19 @@ pipeline {
} }
} }
stage('Build production deliverable') { stage('Build production deliverable') {
when {
expression {
buildArtifact
}
}
steps { steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh ''' #!/usr/local/bin/bash sh ''' #!/usr/local/bin/bash
ZIP_FILE="url-shortener_${BRANCH_NAME}_$(date "+%Y-%m-%d_%H-%M-%S").tgz" ZIP_FILE="url-shortener_${BRANCH_NAME}_$(date "+%Y-%m-%d_%H-%M-%S").tgz"
CUR_DIR=$(pwd) CUR_DIR=$(pwd)
bundle config set --local without 'test' bundle config set --local without 'test'
bundle clean bundle config set --local path "vendor"
bundle install
mkdir -p /tmp/url-shortener mkdir -p /tmp/url-shortener
cp -R * /tmp/url-shortener cp -R * /tmp/url-shortener
cp .env.rb /tmp/url-shortener/ cp .env.rb /tmp/url-shortener/
@ -83,9 +122,13 @@ pipeline {
} }
} }
stage('Clean up deliverable') { stage('Clean up deliverable') {
when {
expression {
buildArtifact
}
}
steps { steps {
sh 'rm -rf /tmp/url-shortener' sh 'rm -rf /tmp/url-shortener'
sh 'rm -rf *.tgz'
} }
} }
} }