Understanding Jenkins Pipeline and How to Create Pipeline Jobs
This article explains what a Jenkins Pipeline is, outlines its role in CI/CD and DevOps, and provides step‑by‑step instructions for creating pipeline jobs using both inline Pipeline Script and SCM‑based Jenkinsfile approaches, including sample code and GitLab trigger configuration.
1. What is a Pipeline
A Jenkins Pipeline is a workflow framework that runs on Jenkins, connecting tasks that would otherwise run independently on one or multiple nodes, enabling complex process orchestration and visualisation. It is the core feature of Jenkins 2.x that helps Jenkins evolve from CI to CD and supports DevOps practices.
Pipeline consists of a set of plugins that allow Jenkins to implement continuous delivery pipelines, automating the entire software flow from version control to delivery to users or customers.
2. Creating a Pipeline Job
To create a new job, select the Pipeline option when creating a new Jenkins job (see image). The pipeline can be defined in two ways:
Pipeline Script : write the script directly in the script textbox.
Pipeline script from SCM : retrieve the pipeline script (Jenkinsfile) from a source‑code repository such as GitLab, GitHub, or Git.
First method – Pipeline Script
Enter the script directly in the job configuration. Example script:
pipeline{
agent any
stages{
stage("first"){
steps {
echo 'hello world'
}
}
stage("run test"){
steps {
echo 'run test'
}
}
}
post{
always{
echo 'always say goodbay'
}
}
}Second method – Pipeline script from SCM
Configure the job to pull the Jenkinsfile from a repository (see images). You can also add a GitLab trigger within the pipeline script:
pipeline {
agent any
triggers {
cron('1 * * * *')
gitlab(triggerOnPush: true,
triggerOnMergeRequest: true,
branchFilterType: "All",
secretToken: "rvgtcxwufgbcsr56lftzr5a74vhjko0")
}
stages {
stage('pull') {
steps {
echo '拉取代码'
}
}
}
}These configurations allow Jenkins to automatically run pipelines on code changes, scheduled times, or GitLab events, facilitating continuous integration and delivery.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
