This repository was archived by the owner on Aug 29, 2023. It is now read-only.
forked from rahlfinger/gcloud-pubsub-emulator-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
97 lines (87 loc) · 2.61 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def FRESHBUILDS_VERSION = "1.5.0"
def APP_NAME = 'gcloud-pubsub-emulator'
pipeline {
agent {
label "jenkins-python-fbtest"
}
options {
timeout(time: 15, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr: '30', daysToKeepStr: '30', artifactNumToKeepStr: '30', artifactDaysToKeepStr: '30'))
}
environment {
ARTIFACTORY_CREDENTIALS = credentials('freshbooks-bot-artifactory')
SLACK_TOKEN = credentials('slack-bot-token')
}
stages {
stage('Build and publish') {
steps {
container('python') {
sh "docker build --no-cache -t gcr.io/freshbooks-builds/${APP_NAME}:${env.BRANCH_NAME} ."
}
}
post {
success {
container('python') {
script {
sh "docker push gcr.io/freshbooks-builds/${APP_NAME}:${env.BRANCH_NAME}"
if (env.BRANCH_NAME == 'master') {
sh "docker tag gcr.io/freshbooks-builds/${APP_NAME}:${env.BRANCH_NAME} gcr.io/freshbooks-builds/${APP_NAME}:latest"
sh "docker push gcr.io/freshbooks-builds/${APP_NAME}:latest"
}
}
}
}
}
}
}
post {
always {
container('python') {
sh "sudo pip install -i https://${ARTIFACTORY_CREDENTIALS_USR}:${ARTIFACTORY_CREDENTIALS_PSW}@freshbooks.jfrog.io/freshbooks/api/pypi/pypi/simple freshbuilds==${FRESHBUILDS_VERSION}"
notifyStatus(currentBuild, SLACK_TOKEN)
}
}
}
}
def notifyStatus(build, slackToken) {
commits = fetchGitCommits(build)
status = build.currentResult
sh "freshbuilds slack -st ${slackToken} notify_status -s ${status} -r . -c ${commits}"
}
def fetchGitCommits(build) {
def commits = []
if (!(env.BRANCH_NAME ==~ /^PR-\d+$/)) {
commits = getBuildChangeSets(build)
}
return commits.size() == 0 ? commitHashForBuild(build) : commits.join(',')
}
@NonCPS
def getBuildChangeSets(build) {
def commits = []
if (build == null) {
return commits
}
if (build.rawBuild.changeSets.size() == 0) {
commits.addAll(getBuildChangeSets(build.getPreviousBuild()))
} else {
build.rawBuild.changeSets.each {
it.each {
commits.add(it.commitId)
}
}
}
return commits
}
@NonCPS
def commitHashForBuild(build) {
def scmAction = build?.rawBuild?.actions.find {
action -> action instanceof jenkins.scm.api.SCMRevisionAction
}
if (scmAction?.revision == null) {
return "${GIT_COMMIT}"
}
else if (scmAction?.revision instanceof org.jenkinsci.plugins.github_branch_source.PullRequestSCMRevision) {
return scmAction?.revision.getPullHash()
}
return scmAction?.revision.getHash()
}