node{
sh"""
mkdir('foo')
"""
dir ('foo') {
git branch: "<ref spec>", changelog: false, poll: false, url: '<clone url>'
......
}
}
Friday, 17 July 2020
In Jenkins, how to checkout a project into a specific directory (using GIT)
Thursday, 16 July 2020
passing variable to bash script in a jenkins pipeline job
def UNIQUE = sh(returnStdout: true, script: 'uuidgen').trim()
from : https://stackoverflow.com/questions/40323490/passing-variable-to-bash-script-in-a-jenkins-pipeline-job
from : https://stackoverflow.com/questions/40323490/passing-variable-to-bash-script-in-a-jenkins-pipeline-job
Sunday, 28 June 2020
How do I make curl ignore the proxy?
curl --noproxy "*" http://www.stackoverflow.com
vi ~/.curlrc
noproxy=*
proxy=yourproxy.com:8080
Replace one substring for another string in shell script
#!/bin/bash
firstString="I love Suzi and Marry"
secondString="Sara"
echo "${firstString/Suzi/$secondString}"
# prints 'I love Sara and Marry'
EXAMPLE 2:
URL="http://hostname/project/branches/Old_Branch/package"
SRC="Old_Branch"
REP="New_Branch"
echo "${URL/$SRC/$REP}"
Loop through an array of strings in Bash?
## declare an array variable
declare -a arr=("element1" "element2" "element3")
## now loop through the above array
for i in "${arr[@]}"
do
echo "$i"
# or do whatever with individual element of the array
done
# You can access them using echo "${arr[0]}", "${arr[1]}" also
In Bash, how can I check if a string begins with some value?
This snippet on the Advanced Bash Scripting Guide says:
# The == comparison operator behaves differently within a double-brackets
# test than within single brackets.
[[ $a == z* ]] # True if $a starts with a "z" (wildcard matching).
[[ $a == "z*" ]] # True if $a is equal to z* (literal matching).
string='My long string'
if [[ $string == *"My long"* ]]; then
echo "It's there!"
fi
Create array in loop from number of arguments
You can use the +=
operator to append to an array.
args=()
for i in "$@"; do
args+=("$i")
done
echo "${args[@]}"
Run bash command on jenkins pipeline
The Groovy script you provided is formatting the first line as a blank line in the resultant script. The shebang, telling the script to run with /bin/bash instead of /bin/sh, needs to be on the first line of the file or it will be ignored.
So instead, you should format your Groovy like this:
stage('Setting the variables values') {
steps {
bash '''#!/bin/bash
echo "hello world"
'''
}
}
Sunday, 7 June 2020
Is there a better way to write this null check, and a non-empty check, in groovy?
There is indeed a Groovier Way.
if(members){
//Some work
}
from : https://stackoverflow.com/questions/17256855/is-there-a-better-way-to-write-this-null-check-and-a-non-empty-check-in-groovy/17256864
Check if a file exists in jenkins pipeline
def exists = fileExists 'file'
if (exists) {
echo 'Yes'
} else {
echo 'No'
}
from : https://stackoverflow.com/questions/38534781/check-if-a-file-exists-in-jenkins-pipeline
Friday, 29 May 2020
Sonar_Integration_with_Jenkins.MD
SonarQube Integration with Jenkins
Integration SonarQube server with Jenkins is necessary to store your reports. Follow below steps to enable that.
Follow this in YouTube
Prerequisites
- SonarQube Server Get Help here
- Jenkins Server Get Help here
Implementation
Login to Jenkins server and install sonarqube scanner.
- SonarQube scanner URL : https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
- Package : https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.2.0.1227-linux.zip
# wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.2.0.1227-linux.zip
# unzip sonar-scanner-cli-3.2.0.1227-linux.zip
# mv sonar-scanner-3.2.0.1227-linux /opt/sonar_scanner
Set SonarQube server details in sonar-scanner property file
- Sonar properties file: /opt/sonar_scanner/conf/sonar-scanner.properties
- sonar.host.url=http://
<SONAR_SERVER_IP>
:9000
- sonar.host.url=http://
Login to Jenkins GUI console and install " SonarQube scanner" plugin
Manage Jenkins
>Manage Plugins
>Avalable
>SonarQube scanner
Configure SonarQube scanner home path
Manage Jenkins
>Global Tool Configuration
>SonarQube Scanner
- Name :
sonar_scanner
- SONAR_RUNNER_HOME :
/opt/sonar_scanner
- Name :
Configure SonarQube server name and authentication token
Manage Jenkins
>Configure Systems
>SonarQube Servers
- Name :
SonarQube
- ServerURL :
http://<Sonarqube_server>:9000/sonar
- Server
authentication token
To Get Authentication code follow below steps. Login to SonarQube server as a adminMy Account
>Security
>Generate Token
- Name :
Create a job to test SonarQube. Provide below sonar properties details in the job under build
- Build:
Execute SonarQube Scanner
>Analysis properties
(it is mandatary).- sonar.projectKey=
Valaxy
- sonar.projectName=
ValaxyDemo
- sonar.projectVersion=
1.0
- sonar.sources=
/var/lib/jenkins/workspace/$JOB_NAME/<PROJECT_NAME>/src
- sonar.projectKey=
Execute job to get analysis report.
Next Step
from : https://github.com/ValaxyTech/DevOpsDemos/blob/master/SonarQube/Sonar_Integration_with_Jenkins.MD
sonarqube-docker-compose.yml
version: "3" | |
services: | |
sonarqube: | |
image: sonarqube | |
expose: | |
- 9000 | |
ports: | |
- "127.0.0.1:9000:9000" | |
networks: | |
- sonarnet | |
environment: | |
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar | |
- SONARQUBE_JDBC_USERNAME=sonar | |
- SONARQUBE_JDBC_PASSWORD=sonar | |
volumes: | |
- sonarqube_conf:/opt/sonarqube/conf | |
- sonarqube_data:/opt/sonarqube/data | |
- sonarqube_extensions:/opt/sonarqube/extensions | |
- sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins | |
db: | |
image: postgres | |
networks: | |
- sonarnet | |
environment: | |
- POSTGRES_USER=sonar | |
- POSTGRES_PASSWORD=sonar | |
volumes: | |
- postgresql:/var/lib/postgresql | |
- postgresql_data:/var/lib/postgresql/data | |
networks: | |
sonarnet: | |
volumes: | |
sonarqube_conf: | |
sonarqube_data: | |
sonarqube_extensions: | |
sonarqube_bundled-plugins: | |
postgresql: | |
postgresql_data: |
from : https://gist.github.com/Warchant/0d0f0104fe7adf3b310937d2db67b512
Subscribe to:
Posts (Atom)