String cron_string = BRANCH_NAME == "master" ? "H 12 * * 1-5" : ""
pipeline {
agent { label 'linux && !gpu' }
options {
disableConcurrentBuilds()
}
triggers {
cron(cron_string)
}
environment {
GIT_COMMIT_SHORT = sh(returnStdout: true, script:"git rev-parse --short=7 HEAD").trim()
GIT_COMMIT_SUBJECT = sh(returnStdout: true, script:"git log --format=%s -n 1 HEAD").trim()
GIT_COMMIT_AUTHOR = sh(returnStdout: true, script:"git log --format='%an' -n 1 HEAD").trim()
GIT_COMMIT_SUMMARY = "`` ${GIT_COMMIT_SUBJECT} - ${GIT_COMMIT_AUTHOR}"
SLACK_CHANNEL = sh(returnStdout: true, script: "if [[ \"${GIT_BRANCH}\" == \"master\" ]]; then echo \"#kernelops\"; else echo \"#builds\"; fi").trim()
}
stages {
stage('Docker Build') {
steps {
slackSend color: 'none', message: "** ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
sh '''#!/bin/bash
set -exo pipefail
./build | ts
'''
}
}
stage('Test Image') {
steps {
slackSend color: 'none', message: "** ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
sh '''#!/bin/bash
set -exo pipefail
date
./test
'''
}
}
stage('Push Image') {
steps {
slackSend color: 'none', message: "** ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
sh '''#!/bin/bash
set -exo pipefail
date
./push staging
'''
}
}
}
post {
failure {
slackSend color: 'danger', message: "** ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
}
success {
slackSend color: 'good', message: "** ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
}
aborted {
slackSend color: 'warning', message: "** ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
}
}
}