Unable to execute sonarqube scanner with jenkins - sonarqube

I am unable to execute the sonarqube scanner with Jenkins pipeline script.
sonarqube scanner version : 3.3.0
Please suggest.
stage('SonarQube analysis 3') {
steps {
withSonarQubeEnv('sonarqube') {
echo "${SONAR_HOST_URL}"
sh "/var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarQScanner/bin/sonar-scanner -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.login=${SONAR_USERNAME} -Dsonar.password = ${SONAR_PASSWORD} -Dsonar.projectName=HelloWorldMavenProj -Dsonar.projectVersion=4.0 -Dsonar.projectKey=HelloWorldMavenProjKey -Dsonar.sources=/var/lib/jenkins/workspace/SonarPipelineTest"
}}}
Error :
/var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarQScanner/bin/sonar-scanner -Dsonar.host.url=http://xxxxx:9000 -Dsonar.login=admin -Dsonar.password = admin -Dsonar.projectName=HelloWorldMavenProj -Dsonar.projectVersion=4.0 -Dsonar.projectKey=HelloWorldMavenProjKey -Dsonar.sources=/var/lib/jenkins/workspace/SonarPipelineTest
ERROR: Unrecognized option: =

Related

Nullpointer exception after running kubectl and helm command in Jenkinsfile

I am trying to run kubernetes and helm command in the deploy step of the Jenkinsfile but I am facing Nullpointer exception. Below is my code:
stage ('Create and Deploy to k8s Dev Environment') {
//agent {label 'docker-maven-slave'}
options {
skipDefaultCheckout()
}
steps {
withCredentials([string(credentialsId: K8S_DEV_SECRET_ID)]) {
command """
kubectl apply --server=https://10.0.0.0:443 --insecure-skip-tls-verify=false --namespace: "dev-ns" -f -
helm template -f "portal-chart/deploy/values-dev.yaml" portal-chart
"""
}
}
Below are the logs:
[Pipeline] End of Pipeline
hudson.remoting.ProxyException: java.lang.NullPointerException
Caused: hudson.remoting.ProxyException: com.xxx.jenkins.pipeline.library.utils.dispatch.ShellCommandException: Exception calling shell command, 'kubectl apply ... ': null
at command.call(command.groovy:51)
I was able to resolve this. Below is the code:
stage ('Create and Deploy to k8s Dev Environment') {
//agent {label 'docker-maven-slave'}
options {
skipDefaultCheckout()
}
steps {
command """
kubectl apply --server=https://10.0.0.0:443 --insecure-skip-tls-verify=false --namespace: "dev-ns" -f -
helm template -f "portal-chart/deploy/values-dev.yaml" portal-chart
"""
}

How can I trigger Allure 2 jira-plugin without using Maven?

I am trying to get my test results visible in Jira using Allure 2.13.8. The test results are visible but are not displayed as links back to the report, so called backlinks.
Here is my situation.
When I generate an Allure report with maven using allure-maven:
mvn clean test allure:report
an executor.json is created with maven build info inside allure-results dir.
environment {
ALLURE_JIRA_LAUNCH_ISSUES = 'xxx-9'
ALLURE_JIRA_ENABLED = 'true'
ALLURE_JIRA_ENDPOINT = 'http://localhost:8080/rest/'
ALLURE_JIRA_USERNAME = 'xxx'
ALLURE_JIRA_PASSWORD = 'xxxx'
}
stage('Test Execution') {
steps {
withMaven(options: [artifactsPublisher(disabled: true)],
maven: 'MAVEN_HOME') {
sh "mvn clean test -Dtest=ApplyForCreditCardTestsDE,_FailedTests* -Denv=qa-de"
}
}
}
The above env variables trigger the jira-plugin within Allure to export test results and launch to Jira. This works, but this executor.json do not contain links needed to create these backlinks. Just some limited info such as project name, that's it.
When I generate an Allure report with Jenkins Allure plugin:
stage('Generate Test Report') {
steps {
script {
allure([
includeProperties: true,
jdk: '',
properties: [
[key: 'ALLURE_JIRA_LAUNCH_ISSUES',value: 'xxx-9'],
[key: 'ALLURE_JIRA_ENABLED',value: 'true'],
[key: 'ALLURE_JIRA_ENDPOINT',value: 'http://localhost:8080/rest/'],
[key: 'ALLURE_JIRA_USERNAME',value: 'xxx'],
[key: 'ALLURE_JIRA_PASSWORD',value: 'xxxx']
],
reportBuildPolicy: 'ALWAYS',
results: [[path: 'target/allure-results']]
])
}
}
}
an executor.json is created with jenkins build info inside allure-results dir.
{"buildName":"test #35","buildOrder":"35","reportName":"AllureReport","name":"Jenkins","buildUrl":"http://localhost:8085/job/test/35/","reportUrl":"http://localhost:8085/job/test/35/allure","type":"jenkins","url":"http://localhost:8085/"}
This is what I need to be pushed to Jira.
For some reason I cannot figure out how the jira-plugin can be triggered from this plugin? Or do I need to use Allure Command Line Interface to do this? I'm lost.
If you can help me out that would be much appreciated.

How to configure jenkins pipeline with logstash plugin?

Usecase: I want to send jenkins job console log to elasticsearch, from there to kibana so that i can visualise the data.
I am using logstash plugin to achieve this. For freestyle job logstash plugin configuration is working fine but for jenkins pipeline jobs I am getting all required data like build number, job name, build duration and all but it is not showing the build result i.e., success or failure it is not showing.
I tried in two ways:
1.
stage('send to ES') {
logstashSend failBuild: true, maxLines: -1
}
2.
timestamps {
logstash {
node() {
sh'''
echo 'Hello, World!'
'''
try {
stage('GitSCM')
{
git url: 'github repo.git'
}
stage('Initialize')
{
jdk = tool name: 'jdk'
env.JAVA_HOME = "${jdk}"
echo "jdk installation path is: ${jdk}"
sh "${jdk}/bin/java -version"
sh '$JAVA_HOME/bin/java -version'
def mvnHome = tool 'mvn'
}
stage('Build Stage')
{
def mvnHome = tool 'mvn'
sh "${mvnHome}/bin/mvn -B verify"
}
currentBuild.result = 'SUCCESS'
} catch (Exception err) {
currentBuild.result = 'FAILURE'
}
}
}
}
But in both ways I am not getting build result i.e., success or failure in my elasticsearch or kibana.
Can someone help.
I didn't find a clear way to do that, my solution was add those lines at the end of the Jenkinsfile:
echo "Current result: ${currentBuild.currentResult}"
logstashSend failBuild: true, maxLines: 3
In my case, I dont need it to send all console logs, only one log with the result per job.

helm test via Jenkins pipeline

I'm running a basic groovy Jenkins pipeline as code for establishing a successful connection to a kubernetes cluster. Below is the code snippet which is trying to connect to a k8s cluster and listing all the releases.
stage('Helm list'){
steps{
withCredentials([file(credentialsId: "kubeconfig-gke", variable:"kubeconfig")])
{
helm list -a
}
}
}
I get the following error on Jenkins console output :
groovy.lang.MissingPropertyException: No such property: list for class: groovy.lang.Binding
Possible solutions: class
at groovy.lang.Binding.getVariable(Binding.java:63)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:270)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:289)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:293)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:269)
Run it inside a shell command
steps{
withCredentials([file(credentialsId: "kubeconfig-gke", variable:"kubeconfig")])
{
sh """
helm list -a
"""
}
}
}

Cargo Tomcat 7.X not stopping

Here is my configuration in gradle file for cargo.
cargo {
containerId = 'tomcat7x'
port = httpPort.toInteger()
local {
homeDir = file(cargoHome)
configHomeDir = file(cargoHome)
jvmArgs = 'Dcom.sun.management.jmxremote.port=9092
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -'
installer {
installUrl = 'https://installdirectory/content/groups/public/org/apache/tomcat/tomcat/7.0.57/tomcat-7.0.57.zip'
downloadDir = file("$buildDir/download")
extractDir = file("$buildDir/extract")
}
containerProperties { property 'cargo.tomcat.ajp.port', portFinder.nextAvailable}
extraClasspath = files("../service/service-1.0.0-LOCAL-local.jar",configurations.cargoruntime) }}
Following error it's shows in log while running cargoStopLocal task
WARNING: StandardServer.await: Invalid command '' received
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 9092; nested exception is:
java.net.BindException: Address already in use: JVM_Bind
Nov 20, 2015 4:32:34 PM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: Invalid command '' received
can anyone guide me how to handle this issue , it's not stopping cargo server so my build is failing?

Resources