Resources
- GitHub - jenkinsci/docker - Official Jenkins Docker image (opens in a new tab)
- Jenkins Core - Java API (opens in a new tab)
Cheatsheet
Create credentials programatically
HTTP API
Specific Job API
$JENKINS_URL/<Job>/api
Specific Pipeline API
$JENKINS_URL/<Pipeline>/api
View Configuration as Code of Jenkins instance
$JENKINS_URL/manage/configuration-as-code/viewExport
JSON Schema
$JENKINS_URL/manage/configuration-as-code/schema
Job
-
Job types
-
Freestyle project
-
Pipeline
-
Multibranch Pipeline
-
-
Job DSL can be used to create Jobs such as Pipelines.
Job DSL
-
API Reference
-
Any Jenkins instance
$JENKINS_URL/plugin/job-dsl/api-viewer/index.html
-
Managed version on internet
-
-
Resources
CLI
Jenkins CLI
$JENKINS_URL/jnlpJars/jenkins-cli.jar
Plugin Installation Manager Tool
-
In official Docker image,
/bin/jenkins-plugin-cli
will invoke jar located at/opt/jenkins-plugin-manager.jar
-
Resources
Configuration as Code
-
Resources
Pipeline
-
Presence of the
Jenkinsfile
in the root of a repository makes it eligible forJenkins
to automatically manage and execute jobs based on repository branches. -
The
Jenkinsfile
should contain aPipeline
script, specifying the steps to execute the job. -
Resources
Shared Library
-
One
var
script can only invoke othervar
scripts without approval. -
Resources
- Jenkins Usesr Handbook - Extending with Shared Libraries (opens in a new tab)
- Share a standard Pipeline across multiple projects with Shared Libraries (opens in a new tab)
- Setting up a shared library and seed job in Jenkins - Part 1 (opens in a new tab)
- Setting up a shared library and seed job in Jenkins - Part 2 (opens in a new tab)
Pipeline Snippet Generator
$JENKINS_URL/pipeline-syntax
Directive Generator
$JENKINS_URL/directive-generator
Steps Reference
$JENKINS_URL/pipeline-syntax/html
Global Variables Reference
$JENKINS_URL/pipeline-syntax/globals
Debugg Pipeline as Code
- Use
Replay
to make ad-hoc edits toPipeline
code, and run thePipeline
, repeat until done, copy the code toVCS
for future deployments.
Multibranch Pipeline
-
Jenkins automatically discovers, manages, and executes jobs for multiple source repositories and branches.
-
A
multi-branch pipeline
project always includes aJenkinsfile
in itsrepository root
.Jenkins
automatically creates a sub-project for each branch that it finds in a repository with a Jenkinsfile. -
Resources
Jenkins Templating Engine
Tips
Retrieve Job configuration XML
Declarative Pipeline
upon execution are converted to configuration in XML format.- To retrieve the config after conversion, use
$JENKINS_URL/job/<job-name>/config.xml
Convert Job DSL to configuration XML
- Use Job DSL Playground (opens in a new tab) to check output of the Job DSL.
Use Job configuration XML to guide authoring Job DSL
-
On Jenkins UI, create a Job and save config changes.
-
Get
XML
of theJob
configurationUsing
<JENKINS_URL>/../<JOB_name>/config.xml
-
Get
XML
of yourJob DSL
Using
Job DSL Playground
-
Compare both
XML
config to check the differenceDeclarative Pipelines
are structured similar toXML configurations
. -
Use
configure
function in Job DSL -
Try plugin
XML Job to Job DSL
-
Jenkins plugin - XML Job to Job DSL (opens in a new tab)
Note: Many plugins not supported
-
-
Resources
Caveats
-
Pipeline script from SCM
- GitLab Personal Access Token is not supported as credentials