-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mariano
committed
Jul 7, 2021
1 parent
8152a3a
commit 22b0dc8
Showing
1 changed file
with
30 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,7 @@ properties( | |
) | ||
pipeline | ||
{ | ||
agent { | ||
node { | ||
label 'linux && go' | ||
} | ||
} | ||
agent any | ||
options { | ||
skipDefaultCheckout true | ||
} | ||
|
@@ -27,123 +23,54 @@ pipeline | |
{ | ||
stage('Build package') | ||
{ | ||
environment { | ||
l_workspace = createWSPath() | ||
} | ||
agent{ label "linux/u18.04/go:1.15.13" } | ||
steps | ||
{ | ||
ws("${env.l_workspace}"){ | ||
dir('ohm'){ | ||
checkout scm | ||
script { | ||
env.GITHUB_REPO = sh(script: 'basename $(git remote get-url origin) .git', returnStdout: true).trim() | ||
} | ||
sh ''' | ||
export PATH=$PATH:/usr/local/go/bin | ||
export GOPATH=${l_workspace} | ||
make package | ||
''' | ||
archiveArtifacts artifacts: 'build/**', onlyIfSuccessful: true, fingerprint: true | ||
stash includes: 'build/dist/**', name: 'dist' | ||
} | ||
} | ||
} | ||
post { | ||
cleanup { | ||
cleanWSPath() | ||
checkout scm | ||
script { | ||
env.GITHUB_REPO = sh(script: 'basename $(git remote get-url origin) .git', returnStdout: true).trim() | ||
} | ||
sh ''' | ||
make package | ||
''' | ||
archiveArtifacts artifacts: 'build/**', onlyIfSuccessful: true, fingerprint: true | ||
stash includes: 'build/dist/**', name: 'dist' | ||
} | ||
} | ||
stage('Test') | ||
{ | ||
environment { | ||
l_workspace = createWSPath() | ||
} | ||
agent{ label "linux/u18.04/go:1.15.13" } | ||
steps { | ||
ws("${env.l_workspace}"){ | ||
dir('ohm'){ | ||
checkout scm | ||
sh ''' | ||
export GOROOT=/usr/local/go | ||
export PATH=$PATH:$GOROOT/bin | ||
export GOPATH=${l_workspace} | ||
make test | ||
''' | ||
} | ||
} | ||
checkout scm | ||
sh ''' | ||
make test | ||
''' | ||
} | ||
post { | ||
cleanup { | ||
cleanWSPath() | ||
} | ||
} | ||
} | ||
|
||
stage('Release') { | ||
environment { | ||
l_workspace = createWSPath() | ||
} | ||
when { | ||
buildingTag() | ||
} | ||
agent{ label "linux/u18.04/go:1.15.13" } | ||
steps { | ||
ws("${env.l_workspace}"){ | ||
dir('ohm'){ | ||
unstash 'dist' | ||
sh ''' | ||
export GOROOT=/usr/local/go | ||
export GOPATH=${l_workspace} | ||
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin | ||
go get github.com/github-release/github-release | ||
github-release release --user marianob85 --repo ${GITHUB_REPO} --tag ${TAG_NAME} --name ${TAG_NAME} | ||
for filename in build/dist/*; do | ||
[ -e "$filename" ] || continue | ||
basefilename=$(basename "$filename") | ||
github-release upload --user marianob85 --repo ${GITHUB_REPO} --tag ${TAG_NAME} --name ${basefilename} --file ${filename} | ||
done | ||
''' | ||
} | ||
} | ||
} | ||
post { | ||
cleanup { | ||
cleanWSPath() | ||
} | ||
unstash 'dist' | ||
sh ''' | ||
export GOPATH=${PWD} | ||
go get github.com/github-release/github-release | ||
bin/github-release release --user marianob85 --repo ${GITHUB_REPO} --tag ${TAG_NAME} --name ${TAG_NAME} | ||
for filename in build/dist/*; do | ||
[ -e "$filename" ] || continue | ||
basefilename=$(basename "$filename") | ||
bin/github-release upload --user marianob85 --repo ${GITHUB_REPO} --tag ${TAG_NAME} --name ${basefilename} --file ${filename} | ||
done | ||
''' | ||
} | ||
} | ||
} | ||
post | ||
{ | ||
failure { | ||
notifyFailed() | ||
} | ||
success { | ||
notifySuccessful() | ||
} | ||
unstable { | ||
notifyFailed() | ||
post { | ||
changed { | ||
emailext body: "Please go to ${env.BUILD_URL}", to: '${DEFAULT_RECIPIENTS}', subject: "Job ${env.JOB_NAME} (${env.BUILD_NUMBER}) ${currentBuild.currentResult}".replaceAll("%2F", "/") | ||
} | ||
} | ||
} | ||
|
||
def notifySuccessful() { | ||
echo 'Sending e-mail' | ||
mail (to: '[email protected]', | ||
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) success build", | ||
body: "Please go to ${env.BUILD_URL}."); | ||
} | ||
|
||
def notifyFailed() { | ||
echo 'Sending e-mail' | ||
mail (to: '[email protected]', | ||
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) failure", | ||
body: "Please go to ${env.BUILD_URL}."); | ||
} | ||
|
||
def createWSPath() { | ||
return "${env.WORKSPACE}/${env.BRANCH_NAME}/${env.STAGE_NAME}/${env.BUILD_NUMBER}".replace('%2F', '_').replace(' ', '_') | ||
} | ||
|
||
def cleanWSPath() { | ||
cleanWs deleteDirs: true, patterns: [[pattern: 'env.l_workspace', type: 'INCLUDE'], [pattern: '', type: 'INCLUDE']] | ||
} |