-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
74 lines (59 loc) · 1.93 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
#!groovy
version = "0.0.${env.BUILD_NUMBER}"
repo = "dlish27"
app = "$repo/helloworld-app"
node {
stage('checkout') {
checkout scm
}
def tag = "git-${gitCommit()}"
// Feature branch build steps
stage('docker build/test Helloworld App') {
sh "docker build -t $app:$tag ."
}
stage('integration tests') {
echo "implement integration tests"
}
stage('static code analysis') {
echo "implement static code analysis"
}
// PR steps
if (isPR()) {
stage('e2e') {
echo "Implement e2e"
}
}
// Master steps
if (isMaster()) {
withCredentials([
usernamePassword(credentialsId: 'docker-hub-id', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')
]) {
stage('docker publish') {
sh "docker tag $app:$tag $app:$version"
sh "docker login -u $USERNAME -p $PASSWORD"
sh "docker push $app:$version"
}
}
git branch: 'qa', credentialsId: 'bb7477ad-50e9-4a82-8f97-c49d2fa012e5', poll: false, url: 'https://github.com/dlish/helloworld-infrastructure.git'
setVersion()
sh "git add docker-compose.yml"
sh "git commit -m 'jenkins-bot: Update the Helloworld App -> $version'"
withCredentials([
usernamePassword(credentialsId: 'bb7477ad-50e9-4a82-8f97-c49d2fa012e5', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/dlish/helloworld-infrastructure.git qa"
}
}
}
def gitCommit() {
def commit = sh (returnStdout: true, script: "git rev-parse --short HEAD")
return commit.trim()
}
def setVersion() {
sh "sed -i.bak 's,$app:.*,$app:$version,' docker-compose.yml"
}
def isMaster() {
return env.BRANCH_NAME == "master"
}
def isPR() {
return env.BRANCH_NAME =~ /(?i)^pr-/
}