@Library('SovrinHelpers') _
name = 'sovrin-client-rust'
def err
def publishBranch = (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'devel')
try {
stage('Test') {
parallel 'ubuntu-test':{
node('ubuntu') {
stage('Ubuntu Test') {
testUbuntu()
}
}
}
}
if (!publishBranch) {
echo "${env.BRANCH_NAME}: skip publishing"
return
}
stage('Publish to Cargo') {
node('ubuntu') {
publishToCargo()
}
}
} catch(e) {
currentBuild.result = "FAILED"
node('ubuntu-master') {
sendNotification.fail([slack: publishBranch])
}
err = e
} finally {
if (err) {
throw err
}
currentBuild.result = "SUCCESS"
if (publishBranch) {
node('ubuntu-master') {
sendNotification.success(name)
}
}
}
def testUbuntu() {
try {
echo 'Ubuntu Test: Checkout csm'
checkout scm
echo 'Ubuntu Test: Build docker image'
def testEnv = dockerHelpers.build(name)
testEnv.inside {
echo 'Ubuntu Test: Test'
sh 'cargo update'
try {
sh 'cargo test-xunit'
}
finally {
junit 'test-results.xml'
}
}
}
finally {
echo 'Ubuntu Test: Cleanup'
step([$class: 'WsCleanup'])
}
}
def publishToCargo() {
try {
echo 'Publish to Cargo: Checkout csm'
checkout scm
echo 'Publish to Cargo: Build docker image'
def testEnv = dockerHelpers.build(name)
testEnv.inside {
echo 'Update version'
def suffix = env.BRANCH_NAME == 'master' ? env.BUILD_NUMBER : 'devel-' + env.BUILD_NUMBER;
sh 'chmod -R 777 ci'
sh "ci/update-package-version.sh $suffix"
withCredentials([string(credentialsId: 'cargoSecretKey', variable: 'SECRET')]) {
sh 'cargo login $SECRET'
}
sh 'cargo package --allow-dirty'
sh 'cargo publish --allow-dirty'
}
}
finally {
echo 'Publish to cargo: Cleanup'
step([$class: 'WsCleanup'])
}
}