how do you specify cppcheck parameters in jenkins - jenkins

how do you specify cppcheck parameters in jenkins?
I can see from the console output that the following is being run:
+ cppcheck --output-file=cppcheck.xml --enable=all --inconclusive --xml --xml-version=2 ../
I don't know where the cppcheck parameters are specified

Related

how to create a directory with datestamp as its filename in jenkins pipeline?

bat 'set OutputFolderName=%date:~12,2%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%'
bat 'mkdir %OutputFolderName%'
These two commands should give the correct output but they aren't working.
This is the error I got:
Try multiline bat command as follows:
bat """
set OutputFolderName=%date:~12,2%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%
mkdir %OutputFolderName%
"""
Edit: Updated with snapshots
Have a look at my pipeline snapshot here:
Pipeline Console Output
Creates a folder something like this:

OWASP Dependency-check does not scan any issue with Jenkins pipeline but freestyle job

I am running OWASP dependency-check in Jenkins. However, when i run it with Jenkins freestyle job, it shows 2 vulnerabilities from the report. But with the same source code, i run it with Jenkin pipeline, it shows the report, but 0 vulnerabilities.
Here is my Jenkinsfile:
stage ('Dependency Check') {
steps {
dependencyCheck additionalArguments: '''
-o "./"
-s "./"
-f "ALL"
--prettyPrint''', odcInstallation: 'dependencycheck'
dependencyCheckPublisher pattern: 'dependency-check-report.xml'
}
}
Thank you in advance.

‘Jenkinsfile’ not found

I try to use Jenkinsfile for executing build.ps1 file. However, when I scan multibranch-pipeline, I see Does not meet criteria log. Why Jenkins cannot find file. My repo url is this.
Jenkins version : 2.138.3
Jenkinsfile is:
#!groovy
node {
stage ('Checkout') {
checkout scm
}
stage('Check Env Parameters'){
echo "Branch Name : ${env.GIT_BRANCH}"
echo "Octo Server Address : ${env.octoServer}"
}
stage('Run Cake') {
powershell -File build.ps1 -projectName="Jenkins_PowerShell_Cake_Tutorial" -branchName=${env.GIT_BRANCH} -octoServer=${env.octoServer} -octoApiKey=${env.octoApiKey}
}
}
Jenkinsfile's type is not txt
Jenkin Log:
Jenkins Configuration :
The Jenkinsfile in your repo is named .Jenkinsfile (with a dot as first character). Either rename the file or configure the script path with the dot.
Check Jenkinsfile path if not on the same level provide a relative path. This worked for me.
There is also a bug in Jenkins related to this issue:
https://issues.jenkins-ci.org/browse/JENKINS-54126

Can we define a variable inside a Jenkins parameterized build

My scenario is, I have parameterized build and inside the build section, I have executed shell where I define a variable and then echo to print it. But it doesn't print anything in the console output.
I hope I have made myself clear. Could anyone please answer my question?
current_folder=`date +%Y%m%d-%H%M%S`
echo $current_folder
enter image description here
I'm using Jenkins ver. 2.32.3 and a simple freestyle job, running on mac OS, using an execute shell build step of:
current_folder=`date +%Y%m%d-%H%M%S`
echo $current_folder
Gives output of:
$ /bin/sh -xe /var/folders/kh/4fl0eeldofefmmsfd/T/hudson89388543547899686.sh
++ date +%Y%m%d-%H%M%S
+ current_folder=20180613-081712
+ echo 20180613-081712
20180613-081712
Finished: SUCCESS
In a similar fashion, setting the shell:
#!/bin/bash
current_folder=`date +%Y%m%d-%H%M%S`
echo $current_folder
Gives:
$ /bin/bash /var/folders/kh/by0kd93dfew5fgjhy000h6/T/hudson62702345565786787.sh
20180613-081655
Finished: SUCCESS
The same applies to a parameter that is defined as part of the Jenkins job, underneath the
This project is parameterized checkbox once set. For example, if you have a string parameter called userName with a default value of User1, then you can print it's value in an Execute Shell build step using:
echo $userName
echo ${userName}
echo "In a string ${userName}"
Giving:
User1
User1
In a string User1

Execute SonarQube Scanner within Jenkins 2 Pipeline

I want to execute a "SonarQube Scanner" Step within my Jenkins 2.x Pipeline.
When I try to create a sample groovy within the pipeline-syntax I only get a groovy script of the following format:
step <object of type hudson.plugins.sonar.SonarRunnerBuilder>
Does anyone know what is the correct Step Syntax? E.g. Publish JUnit Report looks like
step([$class: 'JUnitResultArchiver', testResults: ''])
I use the following Versions:
Jenkins 2.11
SonarQube Scanner 2.6.1
SonarQube Plugin 2.4.1
I think I got it.
First you have to retrieve your SonarQube Scanner Tool
def sonarqubeScannerHome = tool name: 'SonarQubeScanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
Then you can call sonar-scanner via Shell:
sh "${sonarqubeScannerHome}/bin/sonar-scanner -e -Dsonar.host.url=..."
env.sonarHome= tool name: 'scanner-2.4', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
withSonarQubeEnv('sonar.installation') { // from SonarQube servers > name
sh "${sonarHome}/bin/sonar-runner -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.login=${SONAR_AUTH_TOKEN} -Dsonar.projectName=xxx -Dsonar.projectVersion=xxx -Dsonar.projectKey=xxx -Dsonar.sources=."
}
You can, instead, just provide the full path to ur sonar-runner. As shown in the below snippet.
def runSonarScan(sonar_url){
withEnv(['SONAR_HOST=' + sonar_url]) {
sh '''
$/opt/sonarqube/sonar-runner-2.4/bin/sonar-runner -e -Dsonar.host.url=${SONAR_HOST}
'''
}
}
If you have specific sonar properties add them as a sonar-project.properties file as shown here Sonar Project Properties

Resources