Skip to content

Commit f471c70

Browse files
authored
Use docker inspect to parse network name (#40)
1 parent 7f1eedf commit f471c70

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

docs/tutorials/jenkins/sonarqube-jenkins/Jenkinsfile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1+
def net = '' // Set the value to 'host' to use host networking.
2+
13
pipeline {
24
agent any
35
stages {
6+
stage ('Prepare') {
7+
steps {
8+
script {
9+
if (net == '') {
10+
// Get the name of the network that Jenkins container is using.
11+
net = sh returnStdout: true, script: 'docker inspect $(hostname) -f \'{{ range $k, $v := .NetworkSettings.Networks }}{{ $k }}{{ end }}\''
12+
}
13+
}
14+
}
15+
}
416
stage('Checkout') {
517
steps {
6-
git "${GIT_URL}"
18+
// Replace the git step below with step that pulls the repository you want to analyze.
19+
git branch: 'main', url: 'https://github.com/cicd-tutorials/feedback.git'
720
}
821
}
922
stage('Analyze') {
1023
agent {
1124
docker {
1225
image 'sonarsource/sonar-scanner-cli'
1326
// In order to be able to use http://sonarqube:9000 we need to be in the same network as Jenkins and SonarQube are in.
14-
args '--net jenkins_default'
27+
args "--net $net"
1528
// To quarantee that the workspace contains the sources pulled in previous stage, we need to use the pipeline level workspace.
1629
reuseNode true
1730
}

0 commit comments

Comments
 (0)