Creating your first Pipeline

2 minute read

Create a Pipeline with the Pipeline plugin using this basic script:

Declarative syntax
Scripted syntax
pipeline { agent { label 'linux'} (1) stages { stage('Build') { (2) steps { git url: 'https://github.com/jglick/simple-maven-project-with-tests.git' (3) sh 'mvn --batch clean package' (4) } } } }
1 The agent directive selects the system that runs the commands. Tasks are run on a node labeled linux.
2 The stage groups together a set of steps to be performed.
3 The git step specifies the repository to use and checks out the source code. If you use Pipeline as Code, the script and the code are stored together, and you do not need to recover the code explicitly.
4 Commands used to build the project.
node('linux'){ (1) stage('Build') { (2) git url: 'https://github.com/jglick/simple-maven-project-with-tests.git' (3) sh 'mvn --batch clean package' (4) } }
1 Step that schedules and runs this stage task on a node with the label linux. The node block is required to tell Jenkins on which system to run the commands.
2 The stage groups together a set of steps to be performed.
3 The git step specifies the repository to use and checks out the source code. If you use Pipeline as Code, the script and the code are stored together, and you do not need to recover the code explicitly.
4 Commands used to build the project.

Pipeline enables you to create complex pipelines, including those with parallel stages and conditional logic gates, and load definitions from version control to share between Pipelines. In this way, pipelines and certain standardized scripts are shared between teams, and script updates are protected and reviewed by an administrator.

More information on complex Pipelines can be found in Automating a project with a Jenkinsfile.