pipeline {
agent {
kubernetes {
inheritFrom 'kaniko'
yamlFile 'agent.pod.yaml'
defaultContainer 'leptodon-build'
yamlMergeStrategy merge()
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '3'))
}
environment {
VERSION = sh(
returnStdout: true,
script: 'cargo metadata --no-deps --format-version=1 | jq ".packages[0].version" --raw-output'
).trim()
NS = 'openanalytics'
REGISTRY = 'registry.openanalytics.eu'
IMAGE = 'leptodon'
CACHE_IMAGE = 'leptodon-cache'
DOCKER_BUILDKIT = '1'
NO_COLOR = 'true'
}
stages {
stage('Prepare Environment') {
steps {
script {
if (env.BRANCH_NAME == 'develop') {
env.TAG = "${env.VERSION}-SNAPSHOT"
} else {
env.TAG = "${env.VERSION}"
}
echo "TAG is set to ${env.TAG}"
}
}
}
stage('License Check') {
steps {
sh "cargo make license-check"
}
}
stage('Linting') {
steps {
sh "cargo make lint"
}
}
stage('Library Unit Tests') {
steps {
sh "cargo make unit-tests"
withChecks('Unit Tests') {
junit "target/nextest/default/junit.xml"
}
}
}
stage('Integration Tests') {
steps {
sh "cargo make integration-tests"
withChecks('Integration Tests') {
junit "overview/end2end/reports/test-report-e2e.xml"
}
}
}
stage('Publish Demo') {
when {
anyOf {
branch 'develop'
branch 'main'
}
}
steps {
container('kaniko') {
sh """
/kaniko/executor \
-v info \
--context ${env.WORKSPACE} \
--cache=true \
--cache-repo ${env.REGISTRY}/${env.NS}/${env.CACHE_IMAGE}-demo \
--destination ${env.REGISTRY}/${env.NS}/${env.IMAGE}-demo:${env.TAG} \
--log-format=text \
--log-timestamp=true \
--dockerfile demo.Dockerfile
"""
}
}
post {
always {
sh "cp /kaniko/jenkins/mem*.log ${env.WORKSPACE}"
archiveArtifacts artifacts: 'mem*.log', fingerprint: true
}
}
}
stage('Package leptodon-proc-macros') {
steps {
sh """
cd proc-macros;
cargo package;
"""
}
post {
success {
sh "cp proc-macros/target/package/*.crate ${env.WORKSPACE}"
archiveArtifacts artifacts: '*.crate', fingerprint: true
}
}
}
stage('Publish leptodon-proc-macros') {
when {
branch 'main'
}
environment {
CARGO_REGISTRY_TOKEN = credentials('cratesio-oajenkins')
}
steps {
sh "cargo make publish-leptodon-proc-macros-if-missing"
}
}
stage('Package Leptodon') {
when {
// Avoid failures on develop when bumping the proc-macros crate version
branch 'main'
}
steps {
retry(3) {
// Pray crates.io finds the newly published crate version after 15s.
sh """
sleep 5;
cargo package;
"""
}
}
post {
success {
sh "cp target/package/*.crate ${env.WORKSPACE}"
archiveArtifacts artifacts: '*.crate', fingerprint: true
}
}
}
stage('Publish Leptodon Crate') {
when {
branch 'main'
}
environment {
CARGO_REGISTRY_TOKEN = credentials('cratesio-oajenkins')
}
steps {
sh "cargo make publish-leptodon-if-missing"
}
}
}
}