-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
75 lines (64 loc) · 2.62 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pipeline {
agent any
environment {
COMMIT_MESSAGE = """${sh(
returnStdout: true,
script: "git --no-pager log --format='medium' -1 ${GIT_COMMIT}"
)}"""
COMMIT_HASH = """${sh(
returnStdout: true,
script: "git describe --always"
)}"""
PYTHON_VERSION = '3.7.2'
PYPIRC_CREDENTIALS = "pypirc-kaden-vt"
DOCKER_REPO = "kadenlnelson/realvalidation"
DOCKER_CREDENTIALS = "docker-hub-kadenlnelson"
}
stages {
stage('Notify Slack') {
steps {
slackSend(color: '#000000', message: "Build Started - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)\n```${env.COMMIT_MESSAGE}```")
}
}
stage('Build & Push Python Distributions') {
agent { docker { image "python:${PYTHON_VERSION}" } }
steps {
sh 'pip install -r requirements.txt'
sh 'rm -rf dist'
sh 'python setup.py sdist bdist_wheel'
script {
SEMVER = """${sh(
returnStdout: true,
script: "python setup.py --version"
)}"""
}
withCredentials([file(credentialsId: "${PYPIRC_CREDENTIALS}", variable: 'PYPIRC')]) {
sh 'twine upload --config-file $PYPIRC dist/*'
}
slackSend (color: '#ffde57', message: "PyPi Package Pushed - https://pypi.org/project/realvalidation/\n```\nTry it out!\n\npip install realvalidation==${SEMVER}```")
}
}
stage('Build & Push Docker Image') {
agent { docker { image 'docker:18.09.2' } }
steps {
script {
def branchName = "${GIT_BRANCH}".replace('/', '_')
def image = docker.build("${DOCKER_REPO}")
docker.withRegistry('', "${DOCKER_CREDENTIALS}") {
image.push(branchName)
image.push("${SEMVER}")
}
}
slackSend (color: '#0db7ed', message: "Docker Image Built & Pushed - https://hub.docker.com/r/kadenlnelson/realvalidation/tags\n```\nTry it out!\n\ndocker run --rm ${DOCKER_REPO}:${SEMVER}```")
}
}
}
post {
failure {
slackSend (color: '#FF0000', message: "Build Failed! - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)")
}
success {
slackSend (color: '#00FF00', message: "Success! - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)")
}
}
}