forked from spy16/droplets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
101 lines (101 loc) · 3.66 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
// CI Pipeline for droplets project
// The stack consists of:
// - Jenkins server with docker
// - Nexus as a private repo
// - SonarQube
// - Fossa API
// BEFORE RUNNING THE PIPELINE:
// - set up credentials for sonar and nexus
// - configure sonar tool
// - configure docker cloud
pipeline {
environment {
sonar_server = '<>'
git_repo = 'https://github.com/Filip3Kx/droplets-ci'
git_branch = 'master'
scanner_home = tool '<>'
fossa_api_key = '<>'
bin_repo = "<nexus url:nexus port>"
docker_registry = '<nexus url:docker reg port>'
docker_registry_image = '<nexus url:docker reg port>/droplets-web-container'
}
agent any
stages {
stage("Git Checkout") {
steps {
git branch: "${git_branch}", url: "${git_repo}"
}
}
stage("Build") {
steps {
sh 'export GOCACHE=~/'
sh 'export GOPATH=~/'
sh 'make all'
}
}
stage("Fossa analysis") {
steps {
sh 'curl -H \'Cache-Control: no-cache\' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash'
sh "FOSSA_API_KEY=${fossa_api_key} fossa analyze"
}
}
stage("SonarQube analysis") {
steps {
withSonarQubeEnv("${sonnar_server}") {
sh """${scanner_home}/bin/sonar-scanner \
-Dsonar.projectKey=droplets \
-Dsonar.projectName=droplets \
-Dsonar.projectVersion=1.0 \
-Dsonar.sources=. \
"""
}
}
}
stage('FOSSA Quality Gate') {
steps {
sh "FOSSA_API_KEY=${fossa_api_key} fossa test"
}
}
stage('SonarQube Quality Gate') {
steps{
timeout(time: 1, unit: 'HOURS') {
waitForQualityGate abortPipeline: true
}
}
}
stage("Archive artifacts"){
steps {
nexusArtifactUploader(
nexusVersion: 'nexus3',
protocol: 'http',
nexusUrl: "${bin_repo}",
groupId: 'Prod',
version: "${env.BUILD_ID}_${env.BUILD_TIMESTAMP}",
repository: 'droplets-repo',
credentialsId: 'nexus',
artifacts: [
[artifactId: 'droplets-pipeline',
classifier: '',
file: 'bin/droplets',
type: 'bin']
]
)
}
}
stage("Build & Push Docker image to nexus") {
steps{
withCredentials([usernamePassword(credentialsId: 'nexus', passwordVariable: 'NEXUS_PASSWORD', usernameVariable: 'NEXUS_USERNAME')]) {
sh "docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWORD ${docker_registry}"
}
sh 'docker build -t droplets-web-container .'
sh "docker tag droplets-web-container ${docker_registry_image}"
sh "docker push ${docker_registry_image}"
}
}
}
post {
always {
mail bcc: '', body: "Build ${env.BUILD_ID} has ended with a ${currentBuild.currentResult} \\n More info at ${env.BUILD_URL}", cc: '', from: '', replyTo: '', subject: "Jenkins job | ${env.BUILD_ID}", to: '<recipients>'
}
}
}