-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
68 lines (66 loc) · 2.29 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
def label = "worker-${UUID.randomUUID().toString()}"
podTemplate(label: label, containers: [
containerTemplate(name: 'maven', image: 'maven:3.5.2-jdk-8', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.8', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'helm', image: 'lachlanevenson/k8s-helm:latest', command: 'cat', ttyEnabled: true)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
nfsVolume(mountPath: '/home/jenkins/workspace/', serverAddress: '10.10.18.20', serverPath: '/k8s_prod/jenkins-agent', readOnly: false),
]) {
node(label) {
def myRepo = checkout scm
def gitCommit = myRepo.GIT_COMMIT
def gitBranch = myRepo.GIT_BRANCH
def shortGitCommit = "${gitCommit[0..10]}"
def previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true)
stage('Test') {
try {
container('maven') {
sh """
pwd
echo "GIT_BRANCH=${gitBranch}" >> /etc/environment
echo "GIT_COMMIT=${gitCommit}" >> /etc/environment
mvn -q -B test
"""
}
junit '**/target/surefire-reports/**/*.xml'
}
catch (exc) {
println "Failed to test - ${currentBuild.fullDisplayName}"
throw(exc)
}
}
stage('Build') {
container('maven') {
sh "mvn -q -B package"
}
}
stage('Create Docker images') {
container('docker') {
sh "docker build -t namespace/my-image:${gitCommit} ."
// withCredentials([[$class: 'UsernamePasswordMultiBinding',
// credentialsId: 'dockerhub',
// usernameVariable: 'DOCKER_HUB_USER',
// passwordVariable: 'DOCKER_HUB_PASSWORD']]) {
// sh """
// docker login -u ${DOCKER_HUB_USER} -p ${DOCKER_HUB_PASSWORD}
// docker build -t namespace/my-image:${gitCommit} .
// docker push namespace/my-image:${gitCommit}
// """
// }
}
}
stage('Run kubectl') {
container('kubectl') {
sh "kubectl get pods"
}
}
stage('Run helm') {
container('helm') {
sh "helm list"
}
}
}
}