-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
136 lines (119 loc) · 4.15 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@Library("nimbus-pipeline-library") _
pipeline {
agent { label 'linux' }
environment {
PERLBREW_ROOT = '/opt/perl5'
PERLBREW = "$PERLBREW_ROOT/bin/perlbrew"
PERL_VERSION = "5.20.3"
}
parameters {
booleanParam(
name: 'DOCKERAPP_FORCE_PUSH',
defaultValue: false,
description: 'Override conditions and push dockerapp'
)
string(
name: 'DOCKERAPP_TAG',
defaultValue: '',
description: 'Override the tag in nimbusapp-test.dockerapp. Requires DOCKERAPP_FORCE_PUSH'
)
}
stages {
stage('Notify Start') {
steps {
script {
notifyStart()
}
}
}
stage('Setup') {
steps {
checkout scm
}
}
stage('Docker Hub') {
when {
anyOf {
allOf {
anyOf {
branch 'master'
branch 'issue-21-22'
}
changeset 'tests/nimbusapp-test.dockerapp'
}
expression { params.DOCKERAPP_FORCE_PUSH }
}
}
steps {
script {
// Assumptions:
// - Github and Docker Hub organizations match
// - Job is in root folder of this instance
pushOpts = """ --namespace "${env.JOB_NAME.split('/')[0]}" """
if (params.DOCKERAPP_FORCE_PUSH && params.DOCKERAPP_TAG) {
pushOpts += """ --tag "${params.DOCKERAPP_TAG}" """
}
}
withCredentials([usernamePassword(credentialsId: '5d4e53f3-62ed-471f-85da-83075e934eaf', passwordVariable: 'HUB_PASS', usernameVariable: 'HUB_USER')]) {
sh 'docker login --username "$HUB_USER" --password-stdin <<< $HUB_PASS'
}
sh 'docker-app validate tests/nimbusapp-test.dockerapp'
sh "docker-app push tests/nimbusapp-test.dockerapp ${pushOpts}"
}
} // Docker Hub
stage('Build') {
steps {
sh """
set -xe
docker build . -t nimbusapp-builder:${env.BRANCH_NAME}
docker run --rm -v "\$PWD:/app" --user 1000:1000 -w /app nimbusapp-builder:${env.BRANCH_NAME} perl build.pl ${env.BRANCH_NAME}
"""
}
}
stage('Test Setup') {
steps {
dir('bats-core') {
git(url: 'https://github.com/bats-core/bats-core')
}
sh '''
(
set -xe
$PWD/bats-core/bin/bats -v
$PERLBREW exec --with $PERL_VERSION perl -V
docker version
docker-compose version
docker-app version
./build/nimbusapp.packed.pl version
) 2>&1 | tee test-versions.txt
'''
}
} // Test Setup
stage('Test') {
steps {
lock('nimbusapp-test') {
sh '''
set -xe
export PATH="$PWD/bats-core/bin:$PWD/bats-core/libexec/bats-core:$PATH"
export NIMBUS_EXE="./build/nimbusapp.packed.pl"
$PERLBREW exec --with "$PERL_VERSION" bats tests --tap | tee bats-tap.log
'''
}
}
post {
always {
step([$class: 'TapPublisher', testResults: 'bats-tap.log'])
}
}
} // Test
stage('Archive') {
steps {
archiveArtifacts artifacts: 'build/nimbusapp.tar.gz,build/nimbusapp.zip,bats-tap.log,test-versions.txt'
}
} // Archive
} // stages
post {
always {
notifyComplete()
}
} // post
} // pipeline