OK, I went a bit further, wrapping scripted pipeline syntax pieces in
script{} pseudo-step, so I actually created this:
stage('Submit the sources to SonarQube') {
environment {
SONAR_SCANNER_OPTS = "-Xmx2G -Xms256m"
}
steps {
script {
def scannerHome = tool 'SonarQube Scanner';
withSonarQubeEnv('SonarQube Local') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
But later on I stuck again, because the agent was not able to find the
sonar-scanner, despite properly formed path to it. I fiddled with that a
bit and found, that the path actually existed on the agent only (docker
host), but was never exposed to the container, where the scanner suppose
to be started according to Mr. Jenkins logic (actually I see no point to
start the sonar-scanner from within the container, checkout happens on
the docker host anyway, so firing up the scanner on the docker host
itself would be much more elegant). So I added 'arg' to my dockerfile
part of the pipeline:
agent {
dockerfile {
dir 'ubuntu-xenial-mysql'
args '-v /Jenkins-CI/tools:/Jenkins-CI/tools'
}
}
So the tools would become available not only on 'persistent' docker host
agent machine, but inside the container as well. For now — submission
has been successful, waiting the analysis and if webhook would work.
Cheers,
Kirill
On 14.06.17 13:31, Kirill Peskov wrote:
> Hi All!
>
> Has anyone manage to get SonarQube Scanner and Quality Gateway working
> in a Declarative Pipeline? I'm actually stuck with that, because the
> only examples on both Jenkins and SonarQube docs are examples for the
> scripted pipeline, not declarative one...
>
>
> SonarQube document:
> https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins
> Jenkins document: https://jenkins.io/doc/pipeline/steps/sonar/
>
>
> Both examples are for scripted pipeline (documentation bug/lint?) and
> neither of them explains what is actually necessary inside the block
> withSonarQubeEnv{} and how to start the scanner (which is located on the
> agent in the 'tools' subfolder. Even more — Jenkins does not recognize
> withSonarQubeEnv{} as 'step' at all :(
>
>
> I think one working example would be enough to understand... To add
> another 5 cents, I have to pass extra -Xms and -Xmx parameters to the
> scanner, otherwise it crashes with OOM (I tested it in a 'freestyle' job).
>
>
> Cheers,
> Kirill
>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/75e23dc3-afab-8546-4e1e-e70313419732%40paranoid.email.
For more options, visit https://groups.google.com/d/optout.