0% found this document useful (0 votes)
56 views

Pipeline (Agent (Label ') Stages (Stage ( Build') (Steps (SH MVN Install') ) ) )

Declarative Pipeline Quick Reference provides an overview of the key elements of Declarative Pipeline syntax in Jenkins, including required elements like pipeline, agent, and stages, and optional elements like environment, options, triggers, and post actions. It gives examples of building a Java application with Maven in a Docker container, archiving and testing only the master branch, with a timeout of 6 hours.

Uploaded by

gvcsvg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Pipeline (Agent (Label ') Stages (Stage ( Build') (Steps (SH MVN Install') ) ) )

Declarative Pipeline Quick Reference provides an overview of the key elements of Declarative Pipeline syntax in Jenkins, including required elements like pipeline, agent, and stages, and optional elements like environment, options, triggers, and post actions. It gives examples of building a Java application with Maven in a Docker container, archiving and testing only the master branch, with a timeout of 6 hours.

Uploaded by

gvcsvg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Declarative Pipeline Quick Reference

Jenkins Pipeline enables users to build complete continuous pipeline {


delivery (CD) pipelines as part of their application code. The agent {
steps to build, test and deliver each application become part docker {
label ‘docker-node’
of the application itself, stored in a Jenkinsfile. Declarative image ‘maven’
Pipeline syntax offers a simple, predefined hierarchy to make args ‘-v /tmp:/tmp -p 80:80’
the creation of pipelines and the associated Jenkinsfiles }
accessible to users of all experience levels. In its simplest }
form, a pipeline runs on an agent and contains stages, while environment {
GIT_COMMITTER_NAME = ‘jenkins’
each stage contains steps that define specific actions. }
options {
timeout(6, HOURS)
pipeline {
}
agent {
stages {
label ‘’
stage(‘Build’) {
}
steps {
stages { sh ‘mvn clean install’
stage(‘Build’) { }
steps{ }
sh ‘mvn install’ stage(‘Archive’) {
} when {
} branch ‘*/master’
} }
} steps {
archive ‘*/target/**/*’
junit ‘*/target/surefire-reports/*.xml’
In addition, Declarative Pipeline syntax also provides }
the ability to control all aspects of the Pipeline execution }
environment in a straightforward format. For example, }
building a Java application with Maven in a Docker container post {
that only archives and tests the “Master” branch and times always {
deleteDir()
out after six hours. }
}
https://jenkins.io/doc/book/pipeline/ }
DECLARATIVE PIPELINE SYNTAX - REQUIRED DECLARATIVE PIPELINE SYNTAX - OPTIONAL
» pipeline - Contains the entire Jenkins Pipeline definition » environment - A sequence of “key = value” pairs
» agent - Defines the agent used for the entire Pipeline to define environment variables
or a stage • credentials(‘<id>’) - Bind credentials to variable
• label - Existing Jenkins node label » options - Options for the entire Pipeline. For example:
• docker - Requires Docker-enabled node • skipDefaultCheckout - Disable auto checkout SCM
- image - Run inside specified Docker image • timeout - Sets timeout for entire Pipeline
- label - Existing Jenkins node label • buildDiscarder - Discard old builds
- args - Arguments for Docker container • disableConcurrentBuilds - Disable concurrent
• dockerfile - Use a local Dockerfile Pipeline runs
- filename - Name of local Dockerfile » tools - Installs pre-defined tools to be available on PATH
- label - Existing Jenkins node label » triggers - Triggers for Pipeline based on schedule,
- args - Arguments for Docker container polling, etc.
» stages - Contains Pipeline stages and steps » parameters - Pipeline parameters that are prompted for
at run time
» stage - A specific named “stage” of the Pipeline » post - Defines actions to be taken when pipeline or stage
• steps - One or more build steps that define the actions completes based on outcome. Conditions execute in order:
in the stage. Contains one or more of the following:
• always - Run regardless of Pipeline status
- Any build step or build wrapper defined in Pipeline • changed - Run if the result of Pipeline has changed
e.g. sh, bat, timeout, echo, archive, junit, etc.
from last run
- parallel (optional) - Execute steps in parallel. • success - Run if Pipeline is successful
May not be used with other steps
• unstable - Run if Pipeline result is unstable
- script (optional) - Execute Scripted Pipeline block
• when (optional) - Runs stage conditionally • failure - Run if the Pipeline has failed
- branch - Stage runs when branch name matches
- expression - Boolean expression Created by CloudBees
• agent, environment, tools and post may also optionally
be defined in stage

You might also like