Top 50 Jenkin Pipeline Interview Questions with Answers

Jenkin Pipeline Interview Questions with Answers

1. What is a Jenkins pipeline?

a) A coding script used to automate software development
b) A graphical user interface for managing Jenkins jobs
c) A tool used to manage Jenkins plugins
d) All of the above

Answer: a)

2. What is the difference between declarative and scripted pipelines?

a) Declarative pipelines use a predefined set of steps, while scripted pipelines allow users to write custom scripts.
b) Declarative pipelines use a graphical user interface, while scripted pipelines are coded by hand.
c) Declarative pipelines support parallelism and stage-level error handling, while scripted pipelines do not.
d) Declarative pipelines are deprecated in favor of scripted pipelines.

Answer: a)

3. What is the purpose of the “agent” directive in a Jenkins pipeline?

a) To specify the location where the pipeline is run
b) To define the steps that make up the pipeline
c) To specify the credentials used to run the pipeline
d) To set environment variables for the pipeline

Answer: a)

4. How do you define a parameter in a Jenkins pipeline?

a) Using the “parameters” directive
b) Using the “property” directive
c) Using the “input” directive
d) Parameters cannot be defined in a Jenkins pipeline

Answer: a)

5. What is a Jenkinsfile?

a) A file that defines a Jenkins pipeline
b) A file that stores Jenkins plugin configurations
c) A file that contains the results of a Jenkins build
d) A file that defines Jenkins global variables

Answer: a)

6. How do you specify a conditional statement in a Jenkins pipeline?

a) Using the “if” directive
b) Using the “when” directive
c) Using the “switch” directive
d) Conditional statements cannot be used in a Jenkins pipeline

Answer: a)

7. What is the purpose of the “input” directive in a Jenkins pipeline?

a) To pause the pipeline and wait for user input
b) To define parameters for the pipeline
c) To specify the location where the pipeline is run
d) To set environment variables for the pipeline

Answer: a)

8. How do you trigger a downstream job in a Jenkins pipeline?

a) Using the “build” directive
b) Using the “trigger” directive
c) Using the “stage” directive
d) Downstream jobs cannot be triggered in a Jenkins pipeline

Answer: a)

9. What is the purpose of the “stage” directive in a Jenkins pipeline?

a) To define steps that make up the pipeline
b) To group pipeline steps into stages
c) To define environment variables for the pipeline
d) To specify the location where the pipeline is run

Answer: b)

10. What is the purpose of the “when” directive in a Jenkins pipeline?

a) To define parallelism in the pipeline
b) To specify conditions that must be met before a step can run
c) To trigger downstream jobs
d) To define custom functions used in the pipeline

Answer: b)

11. How do you define environment variables in a Jenkins pipeline?

a) Using the “properties” directive
b) Using the “pipeline” directive
c) Using the “env” directive
d) Environment variables cannot be defined in a Jenkins pipeline

Answer: c)

12. What is the “stash” and “unstash” commands in Jenkins?

a) Commands used for version control in Jenkins
b) Commands used to archive files in Jenkins
c) Commands used to share files between nodes in a Jenkins pipeline
d) Commands used to install plugins in Jenkins

Answer: c)

13. What is the purpose of the “noStash” directive in a Jenkins pipeline?

a) To ignore archived files during the pipeline run
b) To force files to be archived during the pipeline run
c) To exclude specific stages from the pipeline run
d) The “noStash” directive is not a valid directive in a Jenkins pipeline

Answer: a)

14. What is the “sh” and “bat” commands in Jenkins?

a) Commands used to switch between operating systems in Jenkins
b) Commands used to execute shell scripts and batch files in Jenkins
c) Commands used to archive files in Jenkins
d) Commands used to share files between nodes in a Jenkins pipeline

Answer: b)

15. How do you create a custom function in a Jenkins pipeline?

a) Using the “function” directive
b) Using the “script” directive
c) Custom functions cannot be used in a Jenkins pipeline
d) Using the “plugin” directive

Answer: b)

16. What is the “timeout” directive in a Jenkins pipeline?

a) A directive used to specify the maximum time a step can run before timing out
b) A directive used to pause the pipeline for a specified amount of time
c) A directive used to specify the maximum time the pipeline can run before timing out
d) The “timeout” directive is not a valid directive in a Jenkins pipeline

Answer: a)

17. How do you trigger a Jenkins pipeline using a webhook?

a) Using the Jenkins API
b) Using the “webhook” directive
c) Using a Jenkins plugin
d) Triggering a Jenkins pipeline via webhook is not possible

Answer: a)

18. What is a “floating point” in a Jenkins pipeline?

a) A directive used for floating point arithmetic
b) A Jenkins plugin used for real-time monitoring
c) A Jenkins feature used for dynamic scaling of resources
d) Floating point is not a valid concept in a Jenkins pipeline

Answer: d)

19. What is the purpose of the “post” directive in a Jenkins pipeline?

a) To define cleanup steps that should be run after the pipeline completes
b) To define steps that make up the pipeline
c) To group pipeline steps into stages
d) The “post” directive is not a valid directive in a Jenkins pipeline

Answer: a)

20. What is the purpose of the “tools” directive in a Jenkins pipeline?

a) To specify the tools needed for the pipeline
b) To define custom functions used in the pipeline
c) To group pipeline steps into stages
d) Tools cannot be specified in a Jenkins pipeline

Answer: a)

21. What is the “archiveArtifacts” command in Jenkins?

a) A command used to archive artifacts generated during the pipeline run
b) A command used to deploy artifacts to a remote location
c) A command used to run tests on artifacts generated during the pipeline run
d) The “archiveArtifacts” command is not a valid command in Jenkins

Answer: a)

22. What is the “environment” directive in a Jenkins pipeline?

a) A directive used to define environment variables used by the pipeline
b) A directive used to set the location where the pipeline is run
c) A directive used to specify the tools needed for the pipeline
d) The “environment” directive is not a valid directive in a Jenkins pipeline

Answer: a)

23. What is the “parallel” directive in a Jenkins pipeline?

a) A directive used to define parallelism in the pipeline
b) A directive used to set environment variables for the pipeline
c) A directive used to group pipeline steps into stages
d) The “parallel” directive is not a valid directive in a Jenkins pipeline

Answer: a)

24. What is the “buildDiscarder” directive in a Jenkins pipeline?

a) A directive used to define how long builds should be stored in the pipeline history
b) A directive used to trigger downstream jobs
c) A directive used to archive artifacts generated during the pipeline run
d) The “buildDiscarder” directive is not a valid directive in a Jenkins pipeline

Answer: a)

25. How do you define a global variable in a Jenkins pipeline?

a) Using the “globals” directive
b) Using the “properties” directive
c) Using the “global” directive
d) Global variables cannot be defined in a Jenkins pipeline

Answer: d)

26. What is the “retry” command in Jenkins?

a) A command used to retry a failed step in the pipeline
b) A command used to retry the entire pipeline
c) A command used to retry a downstream job
d) The “retry” command is not a valid command in Jenkins

Answer: a)

27. What is the purpose of the “parameters” directive in a Jenkins pipeline?

a) To define parameters used by the pipeline
b) To specify the location where the pipeline is run
c) To group pipeline steps into stages
d) The “parameters” directive is not a valid directive in a Jenkins pipeline

Answer: a)

28. What is the “cron” command in Jenkins?

a) A command used to trigger a pipeline at a specified time
b) A command used to set environment variables for the pipeline
c) A command used to pause the pipeline for a specified amount of time
d) The “cron” command is not a valid command in Jenkins

Answer: a)

29. What is the “fileExists” command in Jenkins?

a) A command used to test whether a file exists
b) A command used to create a file
c) A command used to archive a file
d) The “fileExists” command is not a valid command in Jenkins

Answer: a)

30. What is the “timestamps” command in Jenkins?

a) A command used to add timestamps to pipeline output
b) A command used to set the location where the pipeline is run
c) A command used to trigger downstream jobs
d) The “timestamps” command is not a valid command in Jenkins

Answer: a)

31. What is the “node” directive in a Jenkins pipeline?

a) A directive used to specify the node where the pipeline is run
b) A directive used to group pipeline steps into stages
c) A directive used to define custom functions used in the pipeline
d) The “node” directive is not a valid directive in a Jenkins pipeline

Answer: a)

32. What is the “params” variable in a Jenkins pipeline?

a) A variable that contains the parameters passed to the pipeline
b) A variable used to store custom programming functions
c) A variable used to store environment variables
d) The “params” variable is not a valid variable in a Jenkins pipeline

Answer: a)

33. What is the “dir” command in Jenkins?

a) A command used to change the working directory in the pipeline
b) A command used to deploy artifacts to a remote location
c) A command used to trigger downstream jobs
d) The “dir” command is not a valid command in Jenkins

Answer: a)

34. What is the “stashSize” directive in a Jenkins pipeline?

a) A directive used to specify the maximum size of archived files
b) A directive used to specify the number of files to archive
c) A directive used to set environment variables for the pipeline
d) The “stashSize” directive is not a valid directive in a Jenkins pipeline

Answer: a)

35. What is the purpose of the “retryWhen” directive in a Jenkins pipeline?

a) To specify the conditions under which a step should be retried
b) To specify the maximum number of times a step should be retried
c) To specify the duration between retries of a failed step
d) The “retryWhen” directive is not a valid directive in a Jenkins pipeline

Answer: a)

36. What is the purpose of the “results” directive in a Jenkins pipeline?

a) To specify the location where the pipeline is run
b) To set environment variables for the pipeline
c) To define cleanup steps that should be run after the pipeline completes
d) The “results” directive is not a valid directive in a Jenkins pipeline

Answer: c)

37. What is the “confirm” command in Jenkins?

a) A command used to pause the pipeline and wait for user input
b) A command used to run tests on artifacts generated during the pipeline run
c) A command used to intelligently retry failed steps in the pipeline
d) The “confirm” command is not a valid command in Jenkins

Answer: a)

38. What is the “mail” command in Jenkins?

a) A command used to send email notifications at a specified stage of the pipeline
b) A command used to archive artifacts generated during the pipeline run
c) A command used to run tests on artifacts generated during the pipeline run
d) The “mail” command is not a valid command in Jenkins

Answer: a)

39. What is the “git” command in Jenkins?

a) A command used to integrate with Git for version control
b) A command used to deploy artifacts to a remote location
c) A command used to archive artifacts generated during the pipeline run
d) The “git” command is not a valid command in Jenkins

Answer: a)

40. What is the purpose of the “inputMessage” directive in a Jenkins pipeline?

a) To define the message displayed when the pipeline is paused for user input
b) To define the message included in email notifications
c) To define a custom error message for failed pipeline steps
d) The “inputMessage” directive is not a valid directive in a Jenkins pipeline

Answer: a)

41. What is the “postBuild” directive in Jenkins?

a) A directive used to define cleanup steps that should be run after the pipeline completes
b) A directive used to specify the location where the pipeline is run
c) A directive used to define custom functions used in the pipeline
d) The “postBuild” directive is not a valid directive in Jenkins

Answer: a)

42. What is the “ignoreErrors” command in Jenkins?

a) A command used to ignore errors during the pipeline run
b) A command used to archive artifacts generated during the pipeline run
c) A command used to pause the pipeline for a specified amount of time
d) The “ignoreErrors” command is not a valid command in Jenkins

Answer: a)

43. What is the “step” command in Jenkins?

a) A command used to define steps in the pipeline
b) A command used to store environment variables
c) A command used to pause the pipeline for a specified amount of time
d) The “step” command is not a valid command in Jenkins

Answer: a)

44. What is the purpose of the “withAnt” directive in a Jenkins pipeline?

a) To specify the Ant version used by the pipeline
b) To set environment variables for the pipeline
c) To archive artifacts generated during the pipeline run
d) The “withAnt” directive is not a valid directive in a Jenkins pipeline

Answer: a)

45. What is the “batLabel” command in Jenkins?

a) A command used to trigger a downstream job on a specified label
b) A command used to deploy artifacts to a remote location
c) A command used to run batch files in the pipeline
d) The “batLabel” command is not a valid command in Jenkins

Answer: c)

46. What is the “try” command in Jenkins?

a) A command used to retry failed steps in the pipeline
b) A command used to run tests on artifacts generated during the pipeline run
c) A command used to archive artifacts generated during the pipeline run
d) The “try” command is not a valid command in Jenkins

Answer: a)

47. What is the purpose of the “unstable” result in Jenkins?

a) To indicate that the pipeline completed but with some issues
b) To indicate that the pipeline failed
c) To indicate that the pipeline has not yet completed
d) The “unstable” result is not a valid concept in Jenkins

Answer: a)

48. What is the “file” command in Jenkins?

a) A command used to create a file in the pipeline
b) A command used to patch a file during the pipeline run
c) A command used to delete a file during the pipeline run
d) The “file” command is not a valid command in Jenkins

Answer: a)

49. What is the purpose of the “stashExists” command in Jenkins?

a) To test whether a specific stash exists
b) To create a stash
c) To store a stash on a remote node
d) The “stashExists” command is not a valid command in Jenkins

Answer: a)

50. What is the purpose of the “properties” directive in a Jenkins pipeline?

a) To set environment variables for the pipeline
b) To define custom functions used in the pipeline
c) To define parameters used by the pipeline
d) To define cleanup steps that should be run after the pipeline completes

Answer: a)

How to execute grovvy script remotely on Jenkins server?

A Jenkins Admin can execute groovy scripts remotely by sending an HTTP POST request to /script/ url or /scriptText/.

curl example via bash

curl -d "script=<your_script_here>" https://jenkins/script
# or to get output as a plain text result (no HTML)
curl -d "script=<your_script_here>" https://jenkins/scriptText

curl submitting groovy file via bash

curl --data-urlencode "script=$(< ./somescript.groovy)" https://jenkins/scriptText

curl submitting groovy file providing username and password via bash

curl --user 'username:password' --data-urlencode "script=$(< ./somescript.groovy)" https://jenkins/scriptText

Jenkins CLI offers the possibility to execute groovy scripts remotely using groovy command or execute groovy interactivelly via groovysh.

java -jar jenkins-cli.jar -noCertificateCheck -s https://10.0.0.91/ groovy disableEnableJobsMatchingPattern.groovy jobPattern=build_git_auto disableOrEnable=disable --username 12345 --password banana

Reference
https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

 

 

Tagged : / / /

How to run/execute groovy script in Jenkins?

Here are the List of way using you can apply grovy code in Jenkins

Method -1: Groovy plugin
This plugin adds the ability to directly execute Groovy code.
More info – https://wiki.jenkins.io/display/JENKINS/Groovy+plugin

Method -2: Jenkins script console
The inbuilt script console is a very useful and powerful Jenkins extension and ideally suits certain types of tasks. This simple but powerful built-in web console allows you to run Groovy scripts on your Jenkins instance (or its slave nodes) from directly within the user interface, and is installed as standard.

To access the console, either navigate to Manage Jenkins and then select Script Console, or simply append /script to your Jenkins host and port, like this for example: http://jenkinshost:8080/script
Running Script Console on the master
This feature can be accessed from “Manage Jenkins” > “Script Console”. Or visit the sub-URL /script on your Jenkins instance.

Running Script Console on agents
Visit “Manage Jenkins” > “Manage Nodes”. Select any node to view the status page. In the menu on the left, a menu item is available to open a “Script Console” on that specific agent.

More info – https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

Method -3: Scriptler Plugins
Scriptler allows you to store/edit groovy scripts and execute it on any of the slaves/nodes… no need to copy/paste groovy code anymore.
More Info – https://wiki.jenkins.io/display/JENKINS/Scriptler+Plugin

Reference

https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

 

Tagged : / / / /

Database of Groovy Script for Jenkins Automation

Here are the list of Groovy Script which can be used in Jenkins to automate the JOBs and CI process. Please add your list in the comment sections as well.

Main Source – 

  • https://github.com/scmgalaxy/jenkins-groovy-script-example
  • https://github.com/cloudbees/jenkins-scripts
  • https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console
  • https://pghalliday.com/jenkins/groovy/sonar/chef/configuration/management/2014/09/21/some-useful-
  • jenkins-groovy-scripts.html
  • https://github.com/cloudbees/jenkins-scripts
  • https://github.com/jenkinsci/jenkins-scripts
  • https://gist.github.com/dnozay/e7afcf7a7dd8f73a4e05
  • https://github.com/samrocketman/jenkins-bootstrap-shared
  • https://github.com/samrocketman/jenkins-script-console-scripts

Example Groovy Script 

Tagged : /

Jenkins Architecture Explained!!!

Jenkins is continuous integration tools which help to integrate other tools to automate the software development activity and repetitive tasks. Jenkins has 2 releases. One, Community version which open source and free and another one is Jenkins Enterprise which is from Cloud bees for enterprise. Jenkins is extremely powerful with vast amount of plug-in supported. Jenkins is one of the most active open source projects so learning and finding the information is easily available on the internet. Jenkins uses master/slave architecture to manage distributed builds.
Jenkins Architecture

Jenkins Architecture is based on the distributed. This has 2 components.

  • Jenkins Server
  • Jenkins Node/Slave/Build Server

Jenkins server is a web dashboard which is nothing but powered from a war file, default run on 8080 ports. Using Dashboard, You can configure the Jobs/Projects but the build takes place in Nodes/Slave. By default one Nodes/Slave is configured and running in Jenkins Server. You can add more Nodes/Slave as well using IP address, user name, Password using the ssh/jnlp/webstart methods.

Your main Jenkins server is the master. In short, the master’s job is to handle scheduling build jobs, dispatching builds to the slaves for the actual execution, monitor the slaves (possibly taking them online and offline as required) and recording and presenting the build results. Even in a distributed architecture, a master instance of Jenkins can also execute build jobs directly.

The job of the slaves is to do as they are configured in the Jenkins Server, which involves executing build jobs dispatched by the master. You can configure a project to always run on a particular slave machine, or a particular type of slave machine, or simply let Jenkins pick the next available slave.
Jenkins is developed using Java and Java is platform independent thus Jenkins servers and nodes/slave can be configured in any servers including Windows, Linux and Mac.

Tagged : / / /

Difference between jenkins and Urbancode build

What is the difference between jenkins and Urbancode build?

jenkins Urbancode build
Jenkins is open framework for automating the repeative tasks and has great plugins which can be used to create entire automated customized continous integration framework. Urbancode build(uBuild) is for automating the repeative tasks and has great limited sets of plugins which can be used to create entire automated continous integration flow.
Jenkins can deliver core CI loop: Detect a change, do a build, test, and deliver feedback and its open framework allows and can be used for software Deployment as well. Urbancode build(uBuild) can deliver core CI loop: Detect a change, do a build, test, and deliver feedback but it can be not be used for deployment. Urbancode Deploy(uDeploy) is another product by IBM which can be used for deployment.
Jenkins can be extended with Large sets of plugins https://plugins.jenkins.io/ Urbancode build(uBuild) can be extended with Limited sets of plugins https://developer.ibm.com/urbancode/plugins/
Jenkins is one of top active Open Source and free developed in Java. Urbancode build(uBuild) is properiety tool by IBM, previously known as Urbancode and developed in Java
Jenkins has plugins which needs extra learning curve by development teams for centrally defined templates Urbancode build(uBuild) has built-in Easy addition of new projects by development teams based on centrally defined templates
Jenkins has Dependency management and but not awareness. Build based on project relationships. Urbancode build(uBuild) has Dependency management and awareness. Build based on project relationships.

My Recommendation – Jenkins

Tagged : / / / /

Jenkins Remote access API Example | Jenkins Tutorial

jenkins-remote-access-api-example
Jenkins Remote access API Example
Jenkins provides machine-consumable remote access API to its functionalities. Currently it comes in three flavors:
XML
JSON with JSONP support
Python
Remote access API is offered in a REST-like style. That is, there is no single entry point for all features, and instead they are available under the “…/api/” URL where “…” portion is the data that it acts on.
For example, if your Jenkins installation sits at http://ci.jruby.org/, visiting http://ci.jruby.org/api/ will show just the top-level API features available – primarily a listing of the configured jobs for this Jenkins instance.
Or if you want to access information about a particular build, e.g. http://ci.jruby.org/job/jruby-base/lastSuccessfulBuild/, then go to http://ci.jruby.org/job/jruby-base/lastSuccessfulBuild/api/ and you’ll see the list of functionalities for that build.
Remote API can be used to do things like these:
Retrieve information from Jenkins for programmatic consumption.
trigger a new build
create/copy jobs
Jobs with parameters, Also see Parameterized Build.
Simple example – sending “String Parameters”:
curl -X POST JENKINS_URL/job/JOB_NAME/build \
  –data token=TOKEN \
  –data-urlencode json='{“parameter”: [{“name”:”id”, “value”:”123″}, {“name”:”verbosity”, “value”:”high”}]}’
Check Jenkins Job Status via REST API
job_status=`curl https://jenkins/view/job/other-job/lastBuild/api/json | grep “\”result\”:\”SUCCESS\””`
if [ -n "$job_status" ] then     # Run your script commands here else   echo "BUILD FAILURE: Other build is unsuccessful or status could not be obtained."   exit 1 fi
How to restart Jenkins manually?
To restart Jenkins manually, you can use either of the following commands:
(jenkins_url)/safeRestart – Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete.
(jenkins_url)/restart – Forces a restart without waiting for builds to complete.
Reference
Tagged : / / / / / / /

Environment variables and properties defined in jenkins | Jenkins Tutorial

Environment variables and properties defined in jenkins

Jenkins Set Environment Variables

When a Jenkins job executes, it sets some environment variables that you may use in your shell script, batch command, Ant script or Maven POM 1. The following table contains a list of all of these environment variables.

Environment Variable Description
BUILD_NUMBER The current build number, such as “153”
BUILD_ID The current build id, such as “2005-08-22_23-59-59” (YYYY-MM-DD_hh-mm-ss, defunct since version 1.597)
BUILD_URL The URL where the results of this build can be found (e.g. http://buildserver/jenkins/job/MyJobName/666/)
NODE_NAME The name of the node the current build is running on. Equals ‘master’ for master node.
JOB_NAME Name of the project of this build. This is the name you gave your job when you first set it up. It’s the third column of the Jenkins Dashboard main page.
BUILD_TAG String of jenkins-${JOB_NAME}-${BUILD_NUMBER}. Convenient to put into a resource file, a jar file, etc for easier identification.
JENKINS_URL Set to the URL of the Jenkins master that’s running the build. This value is used by Jenkins CLI for example
EXECUTOR_NUMBER The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the “build executor status”, except that the number starts from 0, not 1.
JAVA_HOME If your job is configured to use a specific JDK, this variable is set to the JAVA_HOME of the specified JDK. When this variable is set, PATH is also updated to have $JAVA_HOME/bin.
WORKSPACE The absolute path of the workspace.
SVN_REVISION For Subversion-based projects, this variable contains the revision number of the module. If you have more than one module specified, this won’t be set.
CVS_BRANCH For CVS-based projects, this variable contains the branch of the module. If CVS is configured to check out the trunk, this environment variable will not be set.
GIT_COMMIT For Git-based projects, this variable contains the Git hash of the commit checked out for the build (like ce9a3c1404e8c91be604088670e93434c4253f03) (all the GIT_* variables require git plugin)
GIT_URL For Git-based projects, this variable contains the Git url (like git@github.com:user/repo.git or [https://github.com/user/repo.git])
GIT_BRANCH For Git-based projects, this variable contains the Git branch that was checked out for the build (normally origin/master)

Promoted Build Plugin Environment Variables

If you are using the Promoted Build Plugin, you will have access to the following environment variables. This allows you to access information about your Jenkins build since certain environment variables stated above (such as BUILD_TAG now refer to the Promoted Build Plugin’s job.

Environment Variable Replaces Description
PROMOTED_URL BUILD_URL The URL of the original Jenkins job that is involved with the promotion. BUILD_URL now refers to the Promotion’s URL
PROMOTED_JOB_NAME JOB_NAME The name of the original Jenkins job that is involved with the promotion. JOB_NAME now refers to the Promotion’s job’s name
PROMOTED_NUMBER BUILD_NUMBER The Build Number of the job being promoted. BUILD_NUMBER now refer’s the the Promotion Number
PROMOTED_ID BUILD_ID The Build ID (ex. “2005-08-22_23-59-59” (YYYY-MM-DD_hh-mm-ss) ) of the original Jenkins job. BUILD_ID now refer’s to the Promotion’s build ID.

System Properties

Name  ↓ Value   
awt.toolkit sun.awt.X11.XToolkit
com.sun.akuma.Daemon daemonized
executable-war /usr/lib/jenkins/jenkins.war
file.encoding UTF-8
file.encoding.pkg sun.io
file.separator /
java.awt.graphicsenv sun.awt.X11GraphicsEnvironment
java.awt.headless true
java.awt.printerjob sun.print.PSPrinterJob
java.class.path /usr/lib/jenkins/jenkins.war
java.class.version 52.0
java.endorsed.dirs /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/endorsed
java.ext.dirs /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/ext:/usr/java/packages/lib/ext
java.home /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre
java.io.tmpdir /tmp
java.library.path /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.runtime.name OpenJDK Runtime Environment
java.runtime.version 1.8.0_111-b15
java.specification.name Java Platform API Specification
java.specification.vendor Oracle Corporation
java.specification.version 1.8
java.vendor Oracle Corporation
java.vendor.url http://java.oracle.com/
java.vendor.url.bug http://bugreport.sun.com/bugreport/
java.version 1.8.0_111
java.vm.info mixed mode
java.vm.name OpenJDK 64-Bit Server VM
java.vm.specification.name Java Virtual Machine Specification
java.vm.specification.vendor Oracle Corporation
java.vm.specification.version 1.8
java.vm.vendor Oracle Corporation
java.vm.version 25.111-b15
JENKINS_HOME /var/lib/jenkins
jna.loaded true
jna.platform.library.path /usr/lib64:/lib64:/usr/lib:/lib:/usr/lib64/mysql
jnidispatch.path /tmp/jna–1712433994/jna4147775405825940943.tmp
line.separator
mail.smtp.sendpartial true
mail.smtps.sendpartial true
os.arch amd64
os.name Linux
os.version 3.10.0-514.el7.x86_64
path.separator :
sun.arch.data.model 64
sun.boot.class.path /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/classes
sun.boot.library.path /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/lib/amd64
sun.cpu.endian little
sun.cpu.isalist
sun.font.fontmanager sun.awt.X11FontManager
sun.io.unicode.encoding UnicodeLittle
sun.java.command /usr/lib/jenkins/jenkins.war –logfile=/var/log/jenkins/jenkins.log –webroot=/var/cache/jenkins/war –daemon –httpPort=8080 –debug=5 –handlerCountMax=100 –handlerCountMaxIdle=20
sun.java.launcher SUN_STANDARD
sun.jnu.encoding UTF-8
sun.management.compiler HotSpot 64-Bit Tiered Compilers
sun.os.patch.level unknown
svnkit.http.methods Digest,Basic,NTLM,Negotiate
svnkit.ssh2.persistent false
user.country US
user.dir /
user.home /var/lib/jenkins
user.language en
user.name jenkins
user.timezone America/New_York

Environment Variables

Name  ↓ Value   
_ /etc/alternatives/java
HOME /var/lib/jenkins
LANG en_US.UTF-8
LOGNAME jenkins
NLSPATH /usr/dt/lib/nls/msg/%L/%N.cat
PATH /sbin:/usr/sbin:/bin:/usr/bin
PWD /
SHELL /bin/bash
SHLVL 2
USER jenkins
XFILESEARCHPATH /usr/dt/app-defaults/%L/Dt

Plugins

Name  ↓ Version    Enabled    Pinned   
ace-editor 1.1 true false
ant 1.4 true false
antisamy-markup-formatter 1.5 true false
bouncycastle-api 2.16.0 true false
branch-api 1.11.1 true false
build-timeout 1.18 true false
cloudbees-folder 5.16 true false
credentials 2.1.10 true false
credentials-binding 1.10 true false
display-url-api 0.5 true false
durable-task 1.12 true false
email-ext 2.53 true false
external-monitor-job 1.7 true false
git 3.0.1 true false
git-client 2.2.0 true false
git-server 1.7 true false
github 1.25.1 true false
github-api 1.84 true false
github-branch-source 1.10.1 true false
github-organization-folder 1.5 true false
gradle 1.25 true false
handlebars 1.1.1 true false
icon-shim 2.0.3 true false
jacoco 2.1.0 true false
javadoc 1.4 true false
jira 2.3 true false
jobConfigHistory 2.15 true false
jquery 1.11.2-0 true false
jquery-detached 1.2.1 true false
junit 1.19 true false
ldap 1.13 true false
mailer 1.18 true false
mapdb-api 1.0.9.0 true false
matrix-auth 1.4 true false
matrix-project 1.8 true false
maven-plugin 2.14 true false
momentjs 1.1.1 true false
pam-auth 1.3 true false
pipeline-build-step 2.4 true false
pipeline-graph-analysis 1.3 true false
pipeline-input-step 2.5 true false
pipeline-milestone-step 1.3 true false
pipeline-rest-api 2.4 true false
pipeline-stage-step 2.2 true false
pipeline-stage-view 2.4 true false
plain-credentials 1.3 true false
resource-disposer 0.3 true false
scm-api 1.3 true false
script-security 1.25 true false
sonar 2.5 true false
ssh-credentials 1.12 true false
ssh-slaves 1.12 true false
structs 1.5 true false
subversion 2.7.1 true false
thinBackup 1.9 true false
timestamper 1.8.7 true false
token-macro 2.0 true false
windows-slaves 1.2 true false
workflow-aggregator 2.4 true false
workflow-api 2.8 true false
workflow-basic-steps 2.3 true false
workflow-cps 2.23 true false
workflow-cps-global-lib 2.5 true false
workflow-durable-task-step 2.7 true false
workflow-job 2.9 true false
workflow-multibranch 2.9.2 true false
workflow-scm-step 2.3 true false
workflow-step-api 2.7 true false
workflow-support 2.12 true false
ws-cleanup 0.32 true false

Useful Plugins

https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

Reference

https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
http://jenkins:8080/systemInfo

Tagged : / / / / / / /

Complete guide to use Jenkins CLI / Command line | Jenkins Tutorials

jenkins-cli-command-line
Complete guide to use Jenkins CLI / Command line?
Run Jenkins build from command is very simple in Linux system. If you are using using windows, gitbash is a recommended which has bash shell in built. You can use windows command line as well. Jenkins has support to command line client that allows you to access Jenkins from command line.
To Trigger Jenkins build from command line some prerequisite are there
Jenkins service is running.
Enable security option under “Configure Global Security”
Go to jenkins dashboard in Home page ( e.g http://localhost:8080/ ) -> Manage Jenkins
-> Configure Global Security -> Click on “Enable security” checkbox

You can also configure “Access Control” and “Authorization” option in Global Security page.

Download Jenkins-cli.jar
Download Jenkins-cli.jar from http://<your_jenkins_server_url>/jnlpJars/jenkins-cli.jar. (Here <your_jenkins_server_url> is your respective Jenkins server URL (development or staging))
Go to http://<your_jenkins_server_url>/cli and build your command by following the instructions there.
How to login to Jenkins using commands
If your Jenkins requires authentication, use –username and –password or –password-file options to specify the credentials. To avoid doing this for every command, you can also use the login CLI command once (with the same credentials parameters), and after that you may use other commands without specifying credentials.
Whenever the CLI tries to to connect to the Jenkins server, it offers the before mentioned SSH keys. When the user has those keys but don’t want use them to authenticate, preventing being prompted by the key’s password, it’s possible to use the -noKeyAuth argument. This way the CLI will never try to use the SSH keys available. failure to authenticate by itself does not constitute a fatal error. It will instead try to execute the command anyway, as the anonymous user.
Login Jenkins using username and Password
Jenkins allow us to trigger Jenkins build with any specific user, For that we have to pass username and password in command line.
$ java -jar “/tmp/kitchen/cache/jenkins-cli.jar” -s http://localhost:8080 who-am-i –username jenkins –password foobar
$ java -jar jenkins-cli.jar -s http://myjenkins help –username me –password mypassword
Login Jenkins using public keys
Starting 1.419 (which will be out July 4th), Jenkins CLI supports authentication based on the SSH key pair. Just like CloudBees DEV@cloud (or GitHub, or other similar sites), you interactively login from the web UI, then associate your public keys with your user account. Then CLI will silently authenticates itself using your ~/.ssh/id_rsa, ~/.ssh/id_dsa, or ~/.ssh/identity.
https://help.github.com/articles/generating-an-ssh-key/
Login Jenkins using private keys
You can also pass the priate key as follows
To use the -i option the syntax is as follows:
$ java -jar jenkins-cli.jar -s http://myjenkins help -i ~/.ssh/id_rsa
$ java -jar jenkins-cli.jar [-s JENKINS_URL] [-i PRIVATE_KEY] command [options…] [arguments…]
For compatibility reasons, unless you use the -i option,
Login Jenkins using initialAdminPassword
try user “admin” and password from “Jenkins\secrets\initialAdminPassword”
java -jar jenkins-cli.jar -s http://localhost:8080 who-am-i –username admin –password fe3f1e1624ea4be8873b7a35e28b24be
Login Jenkins using passphrase
Go to http://jenkins-serer:8085/user/admin/configure and set the passphrase in “SSH Public Keys” and use the same passphrase with jenkins commands.
E.g 1 – Getting help
The list of the available commands depends on the server you are talking to. Visit https://jenkins.example.com/cli or use ‘help’ command to list them all:
> java -jar jenkins-cli.jar -s https://jenkins.example.com help [command]
E.g 2 – Run Jenkins Build From Command Line
> java -jar jenkins-cli.jar -s http://<jenkins server>/ build build-name [-c] [-f] [-p] [-r N] [-s] [-v] [-w]
build-name : Name of the job to build
-c  : Check for SCM changes before starting the build, and if there’s no change, exit without doing a build
-f  : Follow the build progress. Like -s only interrupts are not passed through to the build.
-p  : Specify the build parameters in the key=value format.
-s  : Wait until the completion/abortion of the command. Interrupts are passed through to the build.
-v  : Prints out the console output of the build. Use with -s
-w  : Wait until the start of the command
Example  – java -jar jenkins-cli.jar -s http://localhost:8080/ build ‘my-project-build’ –username roop –password roop
E.g 3 – List all jobs under the view: tools
$ java -jar jenkins-cli.jar -s http://jenkins/ list-jobs tools
E.g 4 – Get the configuration of the job: template
$ java -jar jenkins-cli.jar -s http://jenkins/ get-job template > template.xml
E.g 5 – Create a new job based on the configuration
$ java -jar jenkins-cli.jar -s http://jenkins/ create-job new_job_name < new_job_name.xml
E.g 6 – Run groovy script
$ java -jar jenkins-cli.jar -s http://jenkins/ groovy scripts/add_job_to_view.groovy
If there are any parameters in the script, just as:
import jenkins.model.*
if (args.length != 2 ) {
  println “Error on arguments!”
}
def jobName  = args[0] ?: ‘a_job’
def viewName = args[1] ?: ‘a_view’
println jobName + ‘ ‘ + viewName
def v = Jenkins.instance.getView(viewName)
def i = Jenkins.instance.getItemByFullName(jobName)
if (v && i) {
  v.add(i)
}
pass the parameters as:
$ java -jar jenkins-cli.jar -s http://jenkins/ groovy scripts/add_job_to_view.groovy JOB_NAME VIEM_NAME
E.g 7 – Build a job
$ java -jar jenkins-cli.jar -s http://jenkins/ build new_job_name
E.g 8 – Diable a job
$ java -jar jenkins-cli.jar -s http://jenkins/ disable-job new_job_name
E.g 8 – Passing parameters when triggering a job build
Job parameters are a very handy concept. Perhaps you’ve only ever used Jenkins or another CI system to automatically run builds when a remote SCM/git repo changes. You can also trigger builds manually from within Jenkins. And whilst you’re doing that, your job can prompt for parameters to the build.
For example, we have a job named similar to “Deploy XYZ App”. It has the git repo hardcoded in the job like a normal build, but when you press “Build”, it shows a list of options: string fields, drop-down lists, etc.
When the job runs, you can use these values anywhere within your job’s configuration. Its very cool.
But how to pass those same parameters via the CLI? You use the -p key=value flag for each parameter you want to pass.
So our finished product might look like:
$ java -jar jenkins-cli.jar -s http://myjenkins build ‘Deploy XYZ App’ -i ~/.ssh/id_rsa -s -v -p target_env=api.cloudfoundry.com -p branch=master
Commons problems
Operation timed out
$ java -jar jenkins-cli.jar -s YOUR_SERVER_URL help
Exception in thread “main” java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at hudson.cli.CLI.<init>(CLI.java:97)
at hudson.cli.CLI.<init>(CLI.java:82)
at hudson.cli.CLI._main(CLI.java:250)
at hudson.cli.CLI.main(CLI.java:199)
Check that the JNLP port is opened if you are using a firewall on your server. You can configure its value in Jenkins configuration. By default it is set to use a random port.
java.io.IOException: No X-Jenkins-CLI2-Port
java.io.IOException: No X-Jenkins-CLI2-Port among [X-Jenkins, null, Server, X-Content-Type-Options, Connection, X-You-Are-In-Group, X-Hudson, X-Permission-Implied-By, Date, X-Jenkins-Session, X-You-Are-Authenticated-As, X-Required-Permission, Set-Cookie, Expires, Content-Length, Content-Type]
at hudson.cli.CLI.getCliTcpPort(CLI.java:284)
at hudson.cli.CLI.<init>(CLI.java:128)
at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72)
at hudson.cli.CLI._main(CLI.java:473)
at hudson.cli.CLI.main(CLI.java:384)
Suppressed: java.io.IOException: Server returned HTTP response code: 403 for URL: http://citest.gce.px/cli
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at hudson.cli.FullDuplexHttpStream.<init>(FullDuplexHttpStream.java:78)
at hudson.cli.CLI.connectViaHttp(CLI.java:152)
at hudson.cli.CLI.<init>(CLI.java:132)
… 3 more
Solution: Go to Manage Jenkins -> Configure Global Security -> “TCP port for JNLP agents”: choose fixed or random
Reference
Tagged : / / / / / / / /