-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
93 lines (91 loc) · 3.52 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
pipeline {
agent any
environment {
DOCKER = credentials('dockerhub')
DOCKER_REPO = "logsight/logsight-result-api"
SONAR_PROJECT_KEY = "aiops_logsight-result-api"
}
stages {
stage('Test') {
agent {
docker {
image 'python:3.7'
}
}
steps {
sh 'pip install -r requirements.txt'
sh 'PYTHONPATH=$PWD/result_api py.test --junitxml test-report.xml --cov-report xml:coverage-report.xml --cov=result_api tests/unit'
stash name: 'test-reports', includes: '*.xml'
}
post {
always {
junit 'test-report.xml'
archiveArtifacts '*-report.xml'
}
}
}
stage('Linting & SonarQube') {
parallel {
stage('SonarQube') {
agent {
docker {
image 'sonarsource/sonar-scanner-cli'
}
}
steps {
script {
unstash "test-reports"
withSonarQubeEnv('logsight-sonarqube') {
sh """
sonar-scanner -Dsonar.projectKey=$SONAR_PROJECT_KEY -Dsonar.branch.name=$BRANCH_NAME \
-Dsonar.organization=logsight \
-Dsonar.sources=result_api -Dsonar.tests=tests/. \
-Dsonar.inclusions="**/*.py" \
-Dsonar.python.coverage.reportPaths=coverage-report.xml \
-Dsonar.test.reportPath=test-report.xml
"""
}
}
}
}
stage ("Lint Dockerfile") {
agent {
docker {
image 'hadolint/hadolint:latest-debian'
}
}
steps {
sh 'hadolint --format json Dockerfile | tee -a hadolint.json'
}
post {
always {
archiveArtifacts 'hadolint.json'
recordIssues(
tools: [hadoLint(pattern: "hadolint.json", id: "dockerfile")]
)
}
}
}
}
}
stage ("Build and test Docker Image") {
steps {
sh "docker build . -t $DOCKER_REPO:${GIT_COMMIT[0..7]}"
// Add step/script to test (amd64) docker image
}
}
stage ("Build and push Docker Manifest") {
when {
// only run when building a tag (triggered by a release)
// tag name = BRANCH_NAME
buildingTag()
}
steps {
sh "docker buildx create --driver docker-container --name multiarch --use --bootstrap"
sh "echo $DOCKER_PSW | docker login -u $DOCKER_USR --password-stdin"
sh "docker buildx build --push --platform linux/amd64,linux/arm64/v8 -t $DOCKER_REPO:$BRANCH_NAME -t $DOCKER_REPO:latest ."
sh "docker buildx rm"
}
}
}
}