91 lines
2.9 KiB
Groovy
91 lines
2.9 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
NEXUS = credentials('jenkins_nexus')
|
|
NCLAZZ = credentials('nclazz_api_token')
|
|
GITEA_TOKEN = credentials('jenkins_gitea_token')
|
|
|
|
DOCKER_REGISTRY = "docker.nclazz.de"
|
|
DOCKER_GROUP = 'nclazz-bots'
|
|
DOCKER_IMAGE = 'teabot'
|
|
DOCKER_TAG = "${ BRANCH_NAME == "master" ? "latest" : "develop" }"
|
|
DOCKER_VERSION = "1.0.0"
|
|
|
|
DEPLOY_ENV = "production"
|
|
}
|
|
|
|
options {
|
|
timeout(time: 30, unit: "MINUTES")
|
|
}
|
|
|
|
stages {
|
|
stage('Docker Build') {
|
|
agent { label 'docker' }
|
|
steps {
|
|
script {
|
|
docker.withRegistry("https://$DOCKER_REGISTRY", "jenkins_nexus") {
|
|
def apiImage = docker.build("$DOCKER_GROUP/$DOCKER_IMAGE")
|
|
apiImage.push("${env.DOCKER_VERSION}")
|
|
apiImage.push("${env.DOCKER_TAG}")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('Run Deployment') {
|
|
agent { label 'provision' }
|
|
when {
|
|
branch 'master'
|
|
}
|
|
steps {
|
|
deployToSwarm(
|
|
name: 'nclazz-teabot',
|
|
file: "${env.WORKSPACE}/docker-compose.yml",
|
|
forceUpdate: true,
|
|
askApproval: false,
|
|
slackChannel: 'deployment',
|
|
env: [
|
|
PORT: 7008,
|
|
VERSION: env.DOCKER_VERSION,
|
|
AUTH_TOKEN: env.NCLAZZ,
|
|
GITEA_TOKEN: env.GITEA_TOKEN,
|
|
GITEA_BASE_URL: 'https://git.l--n.de/api/v1'
|
|
]
|
|
)
|
|
exposeService(
|
|
name: 'nclazz-teabotbot',
|
|
fqdn: 'teabot.nclazz.de',
|
|
description: 'Gitea bot',
|
|
location: '/',
|
|
backendPort: 7008
|
|
)
|
|
}
|
|
}
|
|
}
|
|
post {
|
|
always {
|
|
cleanWs()
|
|
}
|
|
failure {
|
|
slackSend(
|
|
channel: "notifications",
|
|
color: "danger",
|
|
message: "There is a *build failure* in ${env.JOB_NAME}.\nBuild: ${env.RUN_DISPLAY_URL} "
|
|
)
|
|
}
|
|
unstable {
|
|
slackSend(
|
|
channel: "notifications",
|
|
color: "warning",
|
|
message: "Some tests have failed in ${env.JOB_NAME}.\nBuild: ${env.RUN_DISPLAY_URL} "
|
|
)
|
|
}
|
|
fixed {
|
|
slackSend(
|
|
channel: "notifications",
|
|
color: "good",
|
|
message: "The build ${env.JOB_NAME} completed successfully and is back to normal.\nBuild: ${env.RUN_DISPLAY_URL} "
|
|
)
|
|
}
|
|
}
|
|
} |