-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
54 lines (52 loc) · 2.31 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
def label = "node-${UUID.randomUUID().toString().substring(0, 7)}"
podTemplate(label: label,
containers: [containerTemplate(name: 'node', image: 'node:lts', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'docker', image: 'docker:latest', command: 'cat', ttyEnabled: true)
// containerTemplate(name: 'kubectl', image: 'cnych/kubectl', command: 'cat', ttyEnabled: true)
], serviceAccount: 'jenkins', volumes: [
// hostPathVolume(mountPath: '/home/jenkins/.kube', hostPath: '/root/.kube'),
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')]) {
node(label) {
def repo = checkout scm
def gitCommit = repo.GIT_COMMIT
def gitBranch = repo.GIT_BRANCH
echo gitBranch
def IMAGE_NAME = env.JOB_BASE_NAME
def commitHASH = gitCommit.substring(0, 7)
echo commitHASH
try {
stage('Test') {
container('node') {
sh """
pnpm i
pnpm test:coverage
"""
publishHTML target: [allowMissing : false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : 'coverage/',
reportFiles : 'index.html',
reportName : 'Coverage']
}
}
} finally {
junit 'test-results.xml'
}
stage('Build') {
container('docker') {
sh """
docker version
echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
docker build -t ${CI_REGISTRY}/${CI_REGISTRY_NAMESPACE}/${IMAGE_NAME}:${commitHASH} .
docker push ${CI_REGISTRY}/${CI_REGISTRY_NAMESPACE}/${IMAGE_NAME}:${commitHASH}
docker rmi ${CI_REGISTRY}/${CI_REGISTRY_NAMESPACE}/${IMAGE_NAME}:${commitHASH}
"""
}
}
// stage('Deploy') {
// container('kubectl') {
// sh "kubectl get pods"
// }
// }
}
}