pipeline {
agent none
environment {
SONAR_LOGIN='xxxxxxxxxxxxxxxxxxxxxx'
}
stages {
stage ('Checkout') {
agent any
steps {
sh "rm -rf /var/jenkins_home/workspace/${env.JOB_NAME}/*"
git branch: 'develop', credentialsId: 'xxxxxxxxxxxxxxxxxxxx', url: 'https://github.com/xxxxxx/xxxxxxxx.git'
}
}
stage('Scan') {
agent {
docker {
image 'docker:20.10.6'
args "-v /var/run/docker.sock:/var/run/docker.sock -v /var/jenkins_home/workspace/${env.JOB_NAME}/:/usr/src"
}
}
steps {
dir("/var/jenkins_home/workspace/${env.JOB_NAME}/") {
sh """
ls /usr/src
rm -rf /usr/src/*
ls /usr/src
ls /var/jenkins_home/workspace/${env.JOB_NAME}
cp -r /var/jenkins_home/workspace/${env.JOB_NAME}/* /usr/src/
ls /usr/src
docker run --rm -e SONAR_HOST_URL="http://10.10.10.198:9000/" -e SONAR_LOGIN='${env.SONAR_LOGIN}' -v /var/jenkins_home/workspace/${env.JOB_NAME}/:/usr/src sonarsource/sonar-scanner-cli \
-Dsonar.projectKey=app-sonarqube -Dsonar.sources=./
"""
}
}
}
}
}