To know the environment variables
http://<<system-name>>:8080/env-vars.html
http://localhost:8080/env-vars.html
To know the API of Jenkins
http://localhost:8080/api/
Basic Jenkins example
https://www.theserverside.com/tutorial/Create-a-Jenkins-build-job-A-CI-tutorial-for-beginners
To invoke a build on a project we need to form the REST API as below
JENKINS_URL/job/JOB_NAME/build
Path : http://192.168.43.103:8080/job/FirstSample/build
For more details in term of build refer below
https://wiki.jenkins.io/display/JENKINS/Remote+access+API
http://<<system-name>>:8080/env-vars.html
http://localhost:8080/env-vars.html
To know the API of Jenkins
http://localhost:8080/api/
Basic Jenkins example
https://www.theserverside.com/tutorial/Create-a-Jenkins-build-job-A-CI-tutorial-for-beginners
To invoke a build on a project we need to form the REST API as below
JENKINS_URL/job/JOB_NAME/build
Path : http://192.168.43.103:8080/job/FirstSample/build
For more details in term of build refer below
https://wiki.jenkins.io/display/JENKINS/Remote+access+API
Jenkins hand book
Jenkins Shared library
Sudoers file when using sudo command
Lock and Milestone
To get crumb
curl -u "admin:admin" 'http://192.168.43.103:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
CSRF Protection
https://support.cloudbees.com/hc/en-us/articles/219257077-CSRF-Protection-Explained
https://wiki.jenkins.io/display/JENKINS/CSRF+Protection
how to work out CSRF issue
https://stackoverflow.com/questions/38137760/jenkins-rest-api-create-job
To restart Jenkins from console
JENKINS_URL/restart Eg: http://192.168.43.103:8080/restartMore details about Jenkins restart
https://stackoverflow.com/questions/8072700/how-to-restart-jenkins-manually
To start and stop Jenkins from Linux use the below command
systemctl stop jenkins --> To stop jenkins
systemctl start jenkins --> to start jenkins
systemctl status Jenkins --> to know the status
In suse Linux below commands will work
sudo service jenkins status
sudo service jenkins stop
sudo service jenkins start
sudo service jenkins restart
In the Linux the war file is present in the below location
/usr/lib/Jenkins/
To get the a specific version war file in Linux use the below command
cd tmp
mkdir download
wget http://updates.jenkins-ci.org/download/war/2.204/jenkins.war
wget http://updates.jenkins-ci.org/download/war/<<version_number>>/jenkins.war
Reference links for building REST API call
https://support.cloudbees.com/hc/en-us/articles/218889337-How-to-build-a-job-using-the-REST-API-and-cURL-
https://support.cloudbees.com/hc/en-us/articles/220857567-How-to-create-a-job-using-the-REST-API-and-cURL-
https://stackoverflow.com/questions/8512807/calling-a-jenkins-build-from-outside-of-jenkins
WAS and Jenkins
https://aboullaite.me/continuous-deployment-with-maven-jenkins-and-was/
To pause the deployment you can use option as input
To have the input in script then use the below
script {
input message: "Proceed or Abort",
submitter: "selenium,admin",
ok : "Yes, Proceed."
//parameters: [
// string( name:'username',
// defaultValue: 'user1',
// description: 'Username of the user pressing Ok')]
}
https://jenkins.io/doc/book/pipeline/syntax/#input
Declarative vs Scripted Pipeline
https://e.printstacktrace.blog/jenkins-scripted-pipeline-vs-declarative-pipeline-the-4-practical-differences/
https://www.jenkins.io/doc/book/pipeline/syntax/
https://medium.com/@brianrthompson/scripted-vs-declarative-pipelines-which-to-choose-c6af403f1e97
https://www.edureka.co/community/54705/difference-between-declarative-pipeline-scripted-pipeliine
Shared library in
https://devopscube.com/jenkins-shared-library-tutorial/
https://devopscube.com/create-jenkins-shared-library/
https://tomd.xyz/jenkins-shared-library/
https://jenkins.io/doc/book/pipeline/shared-libraries/
https://jenkins.io/blog/2019/01/08/mpl-modular-pipeline-library/
https://medium.com/@AndrzejRehmann/private-jenkins-shared-libraries-540abe7a0ab7
https://medium.com/spaceapetech/jenkins-pipelines-25ebc1980600
https://stackoverflow.com/questions/46507962/how-can-i-call-a-script-in-the-resources-folder-with-arguments-in-a-jenkinsfile
https://stackoverflow.com/questions/59316211/calling-script-from-resource-folder-in-jenkins-shared-folder
https://stackoverflow.com/questions/40213654/how-to-invoke-bash-functions-defined-in-a-resource-file-from-a-jenkins-pipeline
*************************************************************
shared library best practice
https://bmuschko.com/blog/jenkins-shared-libraries/
https://github.com/jenkinsci/JenkinsPipelineUnit/issues/51
https://github.com/stchar/pipeline-sharedlib-testharness/blob/master/jobs/hello.groovy
http://tdongsi.github.io/blog/2017/12/26/class-in-jenkins-shared-library/
https://stackoverflow.com/questions/51326983/using-jenkins-dynamic-shared-lib-into-pipeline
slave and master
https://github.com/salemove/pipeline-lib
Useful material
https://www.eficode.com/blog/jenkins-groovy-tutorial
to get the changes from last build to current build
https://support.cloudbees.com/hc/en-us/articles/217630098-How-to-access-Changelogs-in-a-Pipeline-Job-
checkout([$class: 'TeamFoundationServerScm',
credentialsConfigurer: [$class: 'AutomaticCredentialsConfigurer'],
projectPath: '$/STG',
serverUrl: TFS_SERVER,
workspaceName: '${JOB_NAME}-${NODE_NAME}'])
script{
println("currentBuild : "+currentBuild);
def changedFiles = []
def changeLogSets = currentBuild.changeSets
for (entries in changeLogSets) {
for (entry in entries) {
for (file in entry.affectedFiles) {
echo "Found changed file: ${file.path}"
changedFiles += "${file.path}"
}
}
}
}
credentialsConfigurer: [$class: 'AutomaticCredentialsConfigurer'],
projectPath: '$/STG',
serverUrl: TFS_SERVER,
workspaceName: '${JOB_NAME}-${NODE_NAME}'])
script{
println("currentBuild : "+currentBuild);
def changedFiles = []
def changeLogSets = currentBuild.changeSets
for (entries in changeLogSets) {
for (entry in entries) {
for (file in entry.affectedFiles) {
echo "Found changed file: ${file.path}"
changedFiles += "${file.path}"
}
}
}
}
https://stackoverflow.com/questions/6260383/how-to-get-list-of-changed-files-since-last-build-in-jenkins-hudson
https://stackoverflow.com/questions/38084806/how-to-get-the-changes-since-the-last-successful-build-in-jenkins-pipeline
https://support.cloudbees.com/hc/en-us/articles/217630098-How-to-access-Changelogs-in-a-Pipeline-Job-
Jenkins environment variables
https://code-maven.com/jenkins-pipeline-environment-variables
https://code-maven.com/jenkins-pipeline-environment-variables
****************************************************************
We can now communicate Linux and windows using powershell
Install powershell in linux
https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1
https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1
https://en.opensuse.org/PowerShell
Install the following plugins as well verify before installing the plugins
Powershell
envinject
************************************************************
Jenkins shared library
https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/Jenkins-Shared-Library-GitHub-Example-Pipeline
https://www.codurance.com/publications/2019/05/25/private-jenkins-shared-libraries
https://devopscube.com/jenkins-shared-library-tutorial/
*****************************************************************
To start slave
https://pravinrajput.wordpress.com/2016/08/02/configure-jenkins-slave-and-connect-to-master/
https://pravinrajput.wordpress.com/2016/08/02/configure-jenkins-slave-and-connect-to-master/
https://wiki.jenkins.io/display/JENKINS/Step+by+step+guide+to+set+up+master+and+agent+machines+on+Windows
*****************************************************
Parallel, stash , unstash
how to avoid @2 or temp for projects
***************************
Variables usage from Jenkins pipeline to shellscript
Variables usage from Jenkins pipeline to shellscript
for (i in [ 'a', 'b', 'c' ]) {
echo i
sh """
echo "from shell i=${i}"
"""
sh '''
echo "from shell i='''+i+''' check"
'''
sh '''
echo "from shell i='''+"${i}"+''' check"
'''
}
https://stackoverflow.com/questions/41539076/how-to-pass-variables-from-jenkinsfile-to-shell-command
https://stackoverflow.com/questions/40323490/passing-variable-to-bash-script-in-a-jenkins-pipeline-job
https://stackoverflow.com/questions/40323490/passing-variable-to-bash-script-in-a-jenkins-pipeline-job
how to set environment variable in scripted pipeline
https://stackoverflow.com/questions/55123079/how-to-set-environment-variables-in-a-jenkins-scripted-pipeline
No comments:
Post a Comment