-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
55 lines (54 loc) · 1.6 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
@Library('pipeline-library') _
pipeline {
agent { label 'docker' }
stages {
stage('Build') {
steps {
sh "docker build --pull -t openstax/cnx-db:dev ."
}
}
stage('Test Container Build') {
steps {
sh "docker run --name ${meta.getContainerName()} -d openstax/cnx-db:dev"
// Give the server time to startup
sh "sleep 20s"
// If this command is successful, then the container is accepting connections
sh "docker run --rm --link ${meta.getContainerName()}:db openstax/cnx-db:dev psql -h db -U postgres -c \"\\l\""
// ^^^ If this is failing, it usually means the base container is out-of-date.
}
post {
always {
sh "docker rm -f ${meta.getContainerName()}"
}
}
}
stage('Publish Dev Container') {
when {
anyOf {
branch 'master'
buildingTag()
}
}
steps {
// 'docker-registry' is defined in Jenkins under credentials
withDockerRegistry([credentialsId: 'docker-registry', url: '']) {
sh "docker push openstax/cnx-db:dev"
}
}
}
stage('Publish Release') {
when { buildingTag() }
environment {
release = meta.version()
}
steps {
withDockerRegistry([credentialsId: 'docker-registry', url: '']) {
sh "docker tag openstax/cnx-db:dev openstax/cnx-db:${release}"
sh "docker tag openstax/cnx-db:dev openstax/cnx-db:latest"
sh "docker push openstax/cnx-db:${release}"
sh "docker push openstax/cnx-db:latest"
}
}
}
}
}