A Jenkinsfile
is a text file that contains the
definition of a Jenkins Pipeline and is checked into source control. Consider
the following Pipeline which implements a basic three-stage continuous delivery
pipeline.
pipeline { agent any stages { stage('Build') { steps { echo 'Building..' } } stage('Test') { steps { echo 'Testing..' } } stage('Deploy') { steps { echo 'Deploying....' } } } }
node { stage('Build') { echo 'Building....' } stage('Test') { echo 'Building....' } stage('Deploy') { echo 'Deploying....' } }
Not all Pipelines will have these same three stages, but it is a good starting point to define them for most projects. The sections below will demonstrate the creation and execution of a simple Pipeline in a test installation of Jenkins.
It is assumed that there is already a source control repository set up for the project and a Pipeline has been defined in Jenkins. |
Using a text editor, ideally one which supports
Groovy
syntax highlighting, create a new Jenkinsfile
in the root directory of the
project.
The Declarative Pipeline example above contains the minimum necessary structure
to implement a continuous delivery pipeline. The agent directive, which is required, instructs Jenkins to allocate an executor and
workspace for the Pipeline. Without an agent
directive, not only is the
Declarative Pipeline not valid, it would not be capable of doing any work! By
default, the agent
directive ensures that the source repository is checked out
and made available for steps in the subsequent stages`
The stages directive and steps directive are also required for a valid Declarative Pipeline as they instruct Jenkins what to execute and in which stage it should be executed.
For more advanced usage with Scripted Pipeline, the example above
|