DevOps.com

  • Latest
    • Articles
    • Features
    • Most Read
    • News
    • News Releases
  • Topics
    • AI
    • Continuous Delivery
    • Continuous Testing
    • Cloud
    • Culture
    • DataOps
    • DevSecOps
    • Enterprise DevOps
    • Leadership Suite
    • DevOps Practice
    • ROELBOB
    • DevOps Toolbox
    • IT as Code
  • Videos/Podcasts
    • Techstrong.tv Podcast
    • Techstrong.tv Video Podcast
    • Techstrong.tv - Twitch
    • DevOps Unbound
  • Webinars
    • Upcoming
    • On-Demand Webinars
  • Library
  • Events
    • Upcoming Events
    • On-Demand Events
  • Sponsored Content
  • Related Sites
    • Techstrong Group
    • Container Journal
    • Security Boulevard
    • Techstrong Research
    • DevOps Chat
    • DevOps Dozen
    • DevOps TV
    • Techstrong TV
    • Techstrong.tv Podcast
    • Techstrong.tv Video Podcast
    • Techstrong.tv - Twitch
  • Media Kit
  • About
  • Sponsor
  • AI
  • Cloud
  • Continuous Delivery
  • Continuous Testing
  • DataOps
  • DevSecOps
  • DevOps Onramp
  • Platform Engineering
  • Low-Code/No-Code
  • IT as Code
  • More
    • Application Performance Management/Monitoring
    • Culture
    • Enterprise DevOps
    • ROELBOB
Hot Topics
  • Azure Migration Strategy: Tools, Costs and Best Practices
  • Blameless Integrates Incident Management Platform With Opsgenie
  • OpenAI Hires 1,000 Low Wage Coders to Retrain Copilot | Netflix Blocks Password Sharing
  • Red Hat Brings Ansible Automation to Google Cloud
  • Three Trends That Will Transform DevOps in 2023

Home » Blogs » DevOps and Open Technologies » How to Use the Jenkins Pipelines

How to Use the Jenkins Pipelines

Avatar photoBy: Pramod Vishwakarma on July 31, 2018 1 Comment

With the introduction of the Pipeline, Jenkins added an embedded Groovy engine, making Groovy the scripting language in the Pipeline’s DSL.

Related Posts
  • How to Use the Jenkins Pipelines
  • Jenkins Community Introduces Blue Ocean, a Radical Evolution of the User Experience That Makes Jenkins the Clear Leader for Continuous Delivery
  • Jenkins 2.0 Advances Continuous Delivery with Native Pipeline Support and Usability Enhancements
    Related Categories
  • Blogs
  • DevOps and Open Technologies
    Related Topics
  • code
  • groovy
  • Jenkins
  • Jenkins Pipeline
Show more
Show less

Here are the steps you need to take to set up a Jenkins Pipeline.

TechStrong Con 2023Sponsorships Available
  1. First, log on to your Jenkins server and select “New Item” from the left panel:

  1. Next, enter a name for your pipeline and select “Pipeline” from the options. Click “Ok” to proceed to the next step:

  1. You can now start working your Pipeline script:

The red box in the middle is where you can start writing your script.

Creating the Jenkins Pipeline Script

Pipelines has specific sentences or elements to define script sections, which follow the Groovy syntax.

Node Blocks

The first block to be defined is the “node”:

A “node” is part of the Jenkins distributed mode architecture, where the workload can be delegated to multiple “agent” nodes.

A “master” node handles all the tasks in your environment. Jenkins agent nodes offloads builds from the master node, thus performing all the pipeline work specified in the node block.  For more details, read about Jenkins Distributed builds.

  • This block is optional, and one could be considered as good practice, since with the code included in this block.
  • Jenkins will schedule and run all the steps once any node is available and creates a specific workspace directory.

Stage Section in Jenkins Pipeline Build

The “stage” section is required to segregate the work category as listed inline:

A specified pipeline will consist of several steps that can be grouped in several stages. For example:

Stage 1Pull code from repositoryPull Code CheckIn
Stage 2Build your project and artifactsBuild Project/Artifacts of Project
Stage 3Deploy your applicationDeploy from centralized repo to specified environment
Stage 4Perform functional testsQA performance will happen
Stage 5Perform performance tests·       (UI and performance can test.

Note: Each of the these can include more than one action.

For example, a stage to deploy your application can consist of copying the files to a defined environment for functional tests and to a dedicated server for performance tests/QA and once files are copied successfully, delivery process will start to deploy on any specified environment.

Each stage block specifies the tasks to be performed:

Stage blocks are also optional, but they are recommended because they provide an organized way of specifying tasks to be executed in the script.

Pipeline Syntax

This section builds on the information introduced in Getting started with Pipeline and should be treated solely as a reference. For more information on how to use Pipeline syntax in practical examples, refer to the Using a Jenkinsfile section of Jenkins chapter.

  • As of version 2.5 of the Pipeline plugin, Pipeline supports two discrete syntaxes, which are detailed below. For the pros and cons of each, see the Syntax Comparison.

“Pipeline Syntax” to access the following page:


“Generate Pipeline Script” will create the desired sentence that can be added to your script immediately.

The Jenkinsfile

Pipeline supports two syntaxes, Declarative (introduced in Pipeline 2.5) and Scripted Pipeline. Both of which support building continuous delivery pipelines. Both may be used to define a Pipeline in either the web UI or with a Jenkinsfile, though it’s generally considered a best practice to create a Jenkinsfile and check the file into the source control repository

Jenkins Scripted Pipeline:

  • For more advanced usage with Scripted Pipeline, the example above node is a crucial first step, as it allocates an executor and workspace for the Pipeline. Since the Jenkinsfile is being pulled directly from source control, Pipeline provides a quick and easy way to access the right revision of the source code:

The checkoutstep will checkout code from source control; scm is a special variable which instructs the checkout step to clone the specific revision which triggered this Pipeline run.

Sandbox Security in Jenkins

Jenkins limits the execution of any Groovy script by providing a sandbox. The option “Use Groovy Sandbox,” shown below, is available in the Pipeline tab, and it allows the scripts to be run by any user without requiring administrator privileges. In this case, the script is run only by using the internal accessible APIs (which allow you to develop your script by using Groovy).

When unchecked, if the script has operations that require approval, an administrator will have to provide them. This method is known as “Script approval.” By default, all Jenkins pipelines run in a Groovy sandbox.

If the option is checked and unauthorized operations are used, the script will fail when run. Both the whitelist and the blacklist of functions can be checked at Script Security’s built-in list.

— Pramod Vishwakarma

Filed Under: Blogs, DevOps and Open Technologies Tagged With: code, groovy, Jenkins, Jenkins Pipeline

« The Software Testing Metrics That Make Or Break DevOps Success
New Alluxio Release Accelerates Cloud Deployments for Analytics and Machine Learning »

Techstrong TV – Live

Click full-screen to enable volume control
Watch latest episodes and shows

Upcoming Webinars

Automating Day 2 Operations: Best Practices and Outcomes
Tuesday, February 7, 2023 - 3:00 pm EST
Shipping Applications Faster With Kubernetes: Myth or Reality?
Wednesday, February 8, 2023 - 1:00 pm EST
Why Current Approaches To "Shift-Left" Are A DevOps Antipattern
Thursday, February 9, 2023 - 1:00 pm EST

Sponsored Content

The Google Cloud DevOps Awards: Apply Now!

January 10, 2023 | Brenna Washington

Codenotary Extends Dynamic SBOM Reach to Serverless Computing Platforms

December 9, 2022 | Mike Vizard

Why a Low-Code Platform Should Have Pro-Code Capabilities

March 24, 2021 | Andrew Manby

AWS Well-Architected Framework Elevates Agility

December 17, 2020 | JT Giri

Practical Approaches to Long-Term Cloud-Native Security

December 5, 2019 | Chris Tozzi

Latest from DevOps.com

Azure Migration Strategy: Tools, Costs and Best Practices
February 3, 2023 | Gilad David Maayan
Blameless Integrates Incident Management Platform With Opsgenie
February 3, 2023 | Mike Vizard
OpenAI Hires 1,000 Low Wage Coders to Retrain Copilot | Netflix Blocks Password Sharing
February 2, 2023 | Richi Jennings
Red Hat Brings Ansible Automation to Google Cloud
February 2, 2023 | Mike Vizard
Three Trends That Will Transform DevOps in 2023
February 2, 2023 | Dan Belcher

TSTV Podcast

On-Demand Webinars

DevOps.com Webinar ReplaysDevOps.com Webinar Replays

GET THE TOP STORIES OF THE WEEK

Most Read on DevOps.com

New Relic Bolsters Observability Platform
January 30, 2023 | Mike Vizard
Jellyfish Adds Tool to Visualize Software Development Workflows
January 31, 2023 | Mike Vizard
OpenAI Hires 1,000 Low Wage Coders to Retrain Copilot | Netflix Blocks Password Sharing
February 2, 2023 | Richi Jennings
Cisco AppDynamics Survey Surfaces DevSecOps Challenges
January 31, 2023 | Mike Vizard
Let the Machines Do It: AI-Directed Mobile App Testing
January 30, 2023 | Syed Hamid
  • Home
  • About DevOps.com
  • Meet our Authors
  • Write for DevOps.com
  • Media Kit
  • Sponsor Info
  • Copyright
  • TOS
  • Privacy Policy

Powered by Techstrong Group, Inc.

© 2023 ·Techstrong Group, Inc.All rights reserved.