2020-11-23 05:15:47 +01:00
|
|
|
library('pipeline-library@bugfix/durable-task-workaround')
|
2019-04-11 19:42:18 +02:00
|
|
|
|
|
|
|
pipeline {
|
|
|
|
options { timestamps() }
|
|
|
|
agent any
|
|
|
|
environment {
|
2019-12-20 20:27:44 +01:00
|
|
|
|
2019-07-18 22:50:57 +02:00
|
|
|
GITHUB_URL = 'git@github.com:RightBrain-Networks/auto-semver.git'
|
2019-12-20 17:29:04 +01:00
|
|
|
GITHUB_KEY = 'rbn-ops github'
|
2019-12-20 17:58:23 +01:00
|
|
|
DOCKER_CREDENTIALS = 'rbnopsDockerHubToken'
|
2019-12-20 17:29:04 +01:00
|
|
|
|
2019-12-20 20:27:44 +01:00
|
|
|
SERVICE = 'auto-semver'
|
|
|
|
SELF_SEMVER_TAG = "master" //Image tag to use for self-versioning
|
2019-04-11 20:59:37 +02:00
|
|
|
|
2019-12-20 18:16:11 +01:00
|
|
|
}
|
2019-04-11 19:42:18 +02:00
|
|
|
stages {
|
2019-04-11 20:59:37 +02:00
|
|
|
//Runs versioning in docker container
|
2019-11-22 21:37:53 +01:00
|
|
|
stage('Self Version') {
|
2019-04-11 19:42:18 +02:00
|
|
|
steps {
|
2019-12-20 18:16:11 +01:00
|
|
|
withCredentials([usernamePassword(credentialsId: env.DOCKER_CREDENTIALS, usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
|
2020-11-23 05:15:47 +01:00
|
|
|
sh("docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD")
|
2019-12-20 18:16:11 +01:00
|
|
|
}
|
2019-12-20 20:24:29 +01:00
|
|
|
runAutoSemver("rightbrainnetworks/auto-semver:${SELF_SEMVER_TAG}")
|
2019-04-11 19:42:18 +02:00
|
|
|
}
|
2019-04-11 20:59:37 +02:00
|
|
|
post{
|
|
|
|
// Update Git with status of version stage.
|
|
|
|
success {
|
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Passed version stage', 'SUCCESS', 'Version')
|
|
|
|
}
|
|
|
|
failure {
|
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Failed version stage', 'FAILURE', 'Version')
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 19:42:18 +02:00
|
|
|
}
|
|
|
|
stage('Build') {
|
|
|
|
steps {
|
|
|
|
|
|
|
|
echo "Building ${env.SERVICE} docker image"
|
|
|
|
|
|
|
|
// Docker build flags are set via the getDockerBuildFlags() shared library.
|
2019-12-20 20:23:10 +01:00
|
|
|
sh "docker build ${getDockerBuildFlags()} -t rightbrainnetworks/auto-semver:${env.VERSION} ."
|
2019-04-11 19:42:18 +02:00
|
|
|
|
|
|
|
|
2019-08-05 19:15:52 +02:00
|
|
|
sh "python setup.py sdist"
|
2019-12-20 21:32:46 +01:00
|
|
|
|
2020-11-23 16:24:59 +01:00
|
|
|
stash includes: "dist/semver-${env.VERSION}.tar.gz", name: 'PACKAGE'
|
2019-04-11 19:42:18 +02:00
|
|
|
}
|
|
|
|
post{
|
|
|
|
// Update Git with status of build stage.
|
|
|
|
success {
|
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Passed build stage', 'SUCCESS', 'Build')
|
|
|
|
}
|
|
|
|
failure {
|
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Failed build stage', 'FAILURE', 'Build')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-28 00:11:43 +01:00
|
|
|
stage('Test') {
|
|
|
|
agent {
|
|
|
|
docker {
|
|
|
|
image "rightbrainnetworks/auto-semver:${env.VERSION}"
|
2020-11-23 05:15:47 +01:00
|
|
|
args "--privileged"
|
2019-12-28 00:11:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
steps
|
|
|
|
{
|
|
|
|
dir('semver')
|
|
|
|
{
|
|
|
|
sh 'python tests.py'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
post{
|
|
|
|
// Update Git with status of test stage.
|
|
|
|
success {
|
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Passed test stage', 'SUCCESS', 'Test')
|
|
|
|
}
|
|
|
|
failure {
|
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Failed test stage', 'FAILURE', 'Test')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-11 19:42:18 +02:00
|
|
|
stage('Push')
|
|
|
|
{
|
2019-12-20 17:54:46 +01:00
|
|
|
steps {
|
|
|
|
|
|
|
|
// Authenticate & push to DockerHub
|
2019-12-20 17:58:23 +01:00
|
|
|
withCredentials([usernamePassword(credentialsId: env.DOCKER_CREDENTIALS, usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
|
2019-12-20 17:54:46 +01:00
|
|
|
sh("""
|
2020-11-23 05:15:47 +01:00
|
|
|
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
|
2019-12-20 20:23:10 +01:00
|
|
|
docker push rightbrainnetworks/auto-semver:${env.VERSION}
|
2019-12-20 17:54:46 +01:00
|
|
|
""")
|
|
|
|
}
|
2019-04-11 19:42:18 +02:00
|
|
|
|
2019-12-20 17:54:46 +01:00
|
|
|
// Copy artifact to S3
|
|
|
|
sh "aws s3 cp `ls -t ./dist/semver-* | head -1` s3://rbn-ops-pkg-us-east-1/${env.SERVICE}/${env.SERVICE}-${env.VERSION}.tar.gz"
|
2019-04-11 19:42:18 +02:00
|
|
|
}
|
2019-04-11 19:45:34 +02:00
|
|
|
post
|
|
|
|
{
|
2019-04-11 19:42:18 +02:00
|
|
|
// Update Git with status of push stage.
|
|
|
|
success {
|
2019-04-11 19:45:34 +02:00
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Passed push stage', 'SUCCESS', 'Push')
|
2019-04-11 19:42:18 +02:00
|
|
|
}
|
|
|
|
failure {
|
2019-04-11 19:45:34 +02:00
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Failed push stage', 'FAILURE', 'Push')
|
2019-04-11 19:42:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-20 17:26:01 +01:00
|
|
|
stage('Publish Release')
|
|
|
|
{
|
|
|
|
when {
|
|
|
|
expression {
|
|
|
|
"${env.SEMVER_STATUS}" == "0" && "${env.BRANCH_NAME}" == "master"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
steps
|
|
|
|
{
|
2019-12-20 21:32:46 +01:00
|
|
|
unstash 'PACKAGE'
|
2019-12-20 17:54:46 +01:00
|
|
|
// Create GitHub Release & Upload Artifacts
|
2020-11-23 16:24:59 +01:00
|
|
|
createGitHubRelease('rbn-opsGitHubToken', 'RightBrain-Networks/auto-semver', "${env.VERSION}",
|
|
|
|
"${env.VERSION}", ["auto-semver.tar.gz" : "dist/semver-${env.VERSION}.tar.gz"])
|
2019-12-20 17:54:46 +01:00
|
|
|
|
|
|
|
// Update DockerHub latest tag
|
|
|
|
sh("""
|
2019-12-20 20:23:10 +01:00
|
|
|
docker tag rightbrainnetworks/auto-semver:${env.VERSION} rightbrainnetworks/auto-semver:latest
|
|
|
|
docker push rightbrainnetworks/auto-semver:latest
|
2019-12-20 17:54:46 +01:00
|
|
|
""")
|
2019-12-20 17:26:01 +01:00
|
|
|
}
|
2019-12-20 17:27:49 +01:00
|
|
|
post
|
|
|
|
{
|
|
|
|
// Update Git with status of release stage.
|
|
|
|
success {
|
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Passed release stage', 'SUCCESS', 'Release')
|
|
|
|
}
|
|
|
|
failure {
|
|
|
|
updateGithubCommitStatus(GITHUB_URL, 'Failed release stage', 'FAILURE', 'Release')
|
|
|
|
}
|
|
|
|
}
|
2019-12-20 17:26:01 +01:00
|
|
|
}
|
2019-04-11 19:47:15 +02:00
|
|
|
}
|
2019-11-26 18:19:06 +01:00
|
|
|
post {
|
|
|
|
success { updateGithubCommitStatus(GITHUB_URL, 'Passed build and test', 'SUCCESS') }
|
|
|
|
failure { updateGithubCommitStatus(GITHUB_URL, 'Failed build and test', 'FAILURE') }
|
2019-04-11 19:48:29 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 19:42:18 +02:00
|
|
|
}
|