-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
41 lines (40 loc) · 1.45 KB
/
Jenkinsfile
File metadata and controls
41 lines (40 loc) · 1.45 KB
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
def net = '' // Set the value to 'host' to use host networking.
pipeline {
agent any
stages {
stage ('Prepare') {
steps {
script {
if (net == '') {
// Get the name of the network that Jenkins container is using.
net = sh returnStdout: true, script: 'docker inspect $(hostname) -f \'{{ range $k, $v := .NetworkSettings.Networks }}{{ $k }}{{ end }}\''
}
}
}
}
stage('Checkout') {
steps {
// Replace the git step below with step that pulls the repository you want to analyze.
git branch: 'main', url: 'https://github.com/cicd-tutorials/feedback.git'
}
}
stage('Analyze') {
agent {
docker {
image 'sonarsource/sonar-scanner-cli'
// In order to be able to use http://sonarqube:9000 we need to be in the same network as Jenkins and SonarQube are in.
args "--net $net"
// To quarantee that the workspace contains the sources pulled in previous stage, we need to use the pipeline level workspace.
reuseNode true
}
}
steps {
// The parameter must match the name you gave for the SonarQube server when configuring it.
withSonarQubeEnv('Sonar') {
// Here, job name is used as the project key and current workspace as the sources location.
sh "sonar-scanner -D'sonar.projectKey=${JOB_NAME}' -D'sonar.sources=${WORKSPACE}'"
}
}
}
}
}