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-cliwill invoke jar located at/opt/jenkins-plugin-manager.jar -
Resources
Configuration as Code
-
Resources
Pipeline
-
Presence of the
Jenkinsfilein the root of a repository makes it eligible forJenkinsto automatically manage and execute jobs based on repository branches. -
The
Jenkinsfileshould contain aPipelinescript, specifying the steps to execute the job. -
Resources
Shared Library
-
One
varscript can only invoke othervarscripts 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
Replayto make ad-hoc edits toPipelinecode, and run thePipeline, repeat until done, copy the code toVCSfor future deployments.
Multibranch Pipeline
-
Jenkins automatically discovers, manages, and executes jobs for multiple source repositories and branches.
-
A
multi-branch pipelineproject always includes aJenkinsfilein itsrepository root.Jenkinsautomatically 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 Pipelineupon 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
XMLof theJobconfigurationUsing
<JENKINS_URL>/../<JOB_name>/config.xml -
Get
XMLof yourJob DSLUsing
Job DSL Playground -
Compare both
XMLconfig to check the differenceDeclarative Pipelinesare structured similar toXML configurations. -
Use
configurefunction 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