-
Notifications
You must be signed in to change notification settings - Fork 9
/
Jenkinsfile
113 lines (113 loc) · 5.05 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
podTemplate(
name: 'jenkins-portcullis',
label: 'jenkins-portcullis',
namespace: 'cicd',
containers: [
containerTemplate(name: 'cppbuild', image: 'maplesond/cppbuild:latest', ttyEnabled: true),
containerTemplate(name: 'gitversion', image: 'maplesond/gitversion:latest', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'sonarscanner', image: 'docker.sdlmapleson.net/sonarscanner:1', ttyEnabled: true),
containerTemplate(name: 'githubrelease', image: 'maplesond/githubrelease:latest', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'docker', image: 'docker', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-slave:3.27-1')
],
volumes: [hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')],
imagePullSecrets: ['docker.sdlmapleson.net'],
cloud: 'kubernetes') {
node('jenkins-portcullis') {
stage('Git') {
checkout(scm)
}
// Only do semantic versioning on master or develop branch for now
if(env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'develop') {
stage('Git Version') {
container('gitversion') {
sh ("""SEMVER=`semver .` && echo "\$SEMVER" > version && ./update_version.sh \$SEMVER""")
}
}
}
// We only have the free sonarqube, so just run on master branch to save time.
if(env.BRANCH_NAME == 'master') {
stage('SonarQube') {
container('sonarscanner') {
withCredentials([string(credentialsId: 'sonarqube-token', variable: 'TOKEN')]) {
sh "sonar-scanner -Dsonar.projectKey=portcullis -Dsonar.sources=src,lib,tests,scripts -Dsonar.exclusions=tests/gtest -Dsonar.login=${TOKEN}"
}
}
}
}
stage('Build') {
container('cppbuild') {
sh "./autogen.sh"
sh "./configure"
sh "make -j4 V=1"
}
}
stage('Test') {
container('cppbuild') {
sh "make -j4 V=1 check"
}
}
stage('Install and Package') {
container('cppbuild') {
sh "make install"
sh "make dist"
}
}
if(env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'develop') {
stage('Docker') {
container('docker') {
// Get the version we previously saved to disk
def versionFile = readFile "version"
SEMVER = versionFile.split('\n')[0]
// Build the image
def image = docker.build("harbor.sdlmapleson.net/portcullis/portcullis:${SEMVER}", "--build-arg VERSION=${SEMVER} .")
image.inside {
sh "portcullis --help || true"
sh "junctools --help || true"
}
// Push to local registry
docker.withRegistry('https://harbor.sdlmapleson.net', 'harbor') {
image.push()
image.push("latest")
if(env.BRANCH_NAME == 'master') {
image.push("stable")
// Dockerhub
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_PASS')]) {
sh "docker login -u $DOCKERHUB_USER -p $DOCKERHUB_PASS"
sh "docker tag harbor.sdlmapleson.net/portcullis/portcullis:${SEMVER} maplesond/portcullis:${SEMVER}"
sh "docker tag harbor.sdlmapleson.net/portcullis/portcullis:${SEMVER} maplesond/portcullis:latest"
sh "docker tag harbor.sdlmapleson.net/portcullis/portcullis:${SEMVER} maplesond/portcullis:stable"
sh "docker push maplesond/portcullis:${SEMVER}"
sh "docker push maplesond/portcullis:latest"
sh "docker push maplesond/portcullis:stable"
}
}
}
}
}
}
if(env.BRANCH_NAME == 'master') {
stage('Github Release') {
container('githubrelease') {
withCredentials([string(credentialsId: 'github-maplesond-portcullis', variable: 'GITHUB_TOKEN')]) {
GITHUB_USER = "maplesond"
GITHUB_REPO = "portcullis"
def versionFile = readFile "version"
SEMVER = versionFile.split('\n')[0]
sh "git remote add github-maplesond https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/maplesond/portcullis.git && git push github-maplesond master"
sh """DESCRIPTION=`git log -1 | tail -n +4` && echo "\$DESCRIPTION" > description"""
def DESCRIPTION = readFile "description"
sh "ls"
sh "github-release release -u ${GITHUB_USER} -s ${GITHUB_TOKEN} --tag ${SEMVER} --repo ${GITHUB_REPO} --description '${DESCRIPTION}'"
sh "github-release upload -u ${GITHUB_USER} -s ${GITHUB_TOKEN} --tag ${SEMVER} --repo ${GITHUB_REPO} --name ${GITHUB_REPO}-${SEMVER}.tar.gz --file ${GITHUB_REPO}-${SEMVER}.tar.gz --label ${GITHUB_REPO}-${SEMVER}.tar.gz"
}
}
}
// This is probably going to be hard but it should be possible to at least start the process in an automatic way.
//stage('Brew update') {
//}
//stage('Conda update') {
//}
}
}
}