How To Create Your First Jenkins Pipeline?

A step-by-step information to creating the Jenkins pipeline

Why Jenkins Pipeline?

Steady Supply (CD) is an important a part of the DevOps lifecycle.

It ensures that the software program/utility builders who create them are at all times manufacturing prepared. For this to occur, the code should be continuously constructed, examined, and deployed as it’s up to date. That is the place Jenkins Pipeline comes into the image.

In DevOps, steady integration and steady supply (CI/CD) is achieved by Jenkins Pipeline. Utilizing Jenkins Pipeline for CD releases the software program sooner and extra often. This helps to include the suggestions into every subsequent launch.

What’s Jenkins Pipeline?

Jenkins Pipeline is a mixture of duties to repeatedly ship software program utilizing Jenkins.

I assume you already know what Jenkins is. If not, take a look at this Udemy course to grasp Jenkins.

A Jenkins pipeline consists of a number of states or levels, and so they run sequentially one after the opposite. JenkinsFile is an easy textual content file used to create a pipeline as code in Jenkins. It incorporates code in Groovy Area Particular Language (DSL), which is straightforward to jot down and human readable.

You possibly can run JenkinsFile individually, or you may also run the pipeline code from the Jenkins Net UI. There are two methods you may create a pipeline with Jenkins.

  • Declarative – a brand new method to create Jenkins Pipeline. Right here you write groovy code with “pipeline” blocks, which is checked into an SCM (Supply Code Administration)
  • Scripted – method of writing groovy code the place the code is outlined in “node” blocks.

Earlier than we get into the demo, should you do not have already got Jenkins put in, set up it first. Be sure Jenkins is operating in your system.

Create a Jenkins pipeline

That is what a Jenkins pipeline move appears to be like like, which consists of a number of levels between builders creating software program (coding) and software program being delivered into manufacturing.

Jenkins pipeline

Let’s create a declarative pipeline.

On the Jenkins dashboard, click on New Merchandise. Then enter an merchandise title, for instance ‘First Pipeline’ and choose the ‘Pipeline’ venture. Then click on, OK.

New Item - Jenkins Pipeline

Click on on the Pipeline tab as proven within the picture beneath and put your JenkinsFile (Groovy Code) code right here.

JenkinsFile Code

pipeline {
         agent any
         levels {
                 stage('Construct') {
                 steps {
                     echo 'Hello, GeekFlare. Beginning to construct the App.'
                 }
                 }
                 stage('Take a look at') {
                 steps {
                    enter('Do you wish to proceed?')
                 }
                 }
                 stage('Deploy') {
                 parallel { 
                            stage('Deploy begin ') {
                           steps {
                                echo "Begin the deploy .."
                           } 
                           }
                            stage('Deploying now') {
                            agent {
                                    docker {
                                            reuseNode true
                                            picture ‘nginx’
                                           }
                                    }
                            
                              steps {
                                echo "Docker Created"
                              }
                           }
                           }
                           }
                 stage('Prod') {
                     steps {
                                echo "App is Prod Prepared"
                              }
                 
              }
}
}

Let me clarify the above blocks.

  • The pipeline block consists of all directions for constructing, testing and delivering software program. It’s an important a part of a Jenkins pipeline.
  • A middleman is assigned to run the pipeline on a node and assign a workspace for the pipeline.
  • a section is a block of steps for constructing, testing, and deploying the applying. Phases are used to visualise the Jenkins Pipeline processes.
  • a step is a single activity to be carried out e.g. create a folder, run a docker picture, delete a file, and many others.

The Groovy code above I take advantage of for the JenkinsFile. Every accessible agent is assigned to the pipeline. Subsequent, I outline the Construct stage and carry out a easy echo step. Then I outlined the check section, the place the step asks whether or not you wish to proceed or not. Then I created an implementation section, by which two extra phases run in parallel. The deploy begin section has a step with an echo command, and the deploy now has a step that will get a docker picture of Nginx on the node. Lastly, there’s a Prod section with a easy echo step.

The pipeline defined above has levels with easy steps that enable you to perceive the way it works. When you learn to create a pipeline, you may add extra complexity and create advanced pipelines as effectively.

After you have the code within the Pipeline tab, click on Apply and Save. Lastly, click on Construct Now to start constructing the Jenkins Pipeline you simply created.

Build now

That is what the UI will seem like when the pipeline is operating. When you’ve got adopted all of the steps accurately, your construct will likely be profitable and the construct will likely be proven in blue shade (#27). If there are errors within the construct, the construct will likely be coloured pink (#27).

Jenkins build 27

Now click on on #27 construct after which click on on Console Output to verify what precisely occurred within the backend when it was operating.

Jenkins Construction

That is what the output will seem like and can finish with a SUCCESS message.

Success Console Output

Began by consumer geekflare
Working in Sturdiness stage: MAX_SURVIVABILITY
[Pipeline] Begin of Pipeline
[Pipeline] node
Working on Jenkins in /var/lib/jenkins/workspace/First Pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Construct)
[Pipeline] echo
Hello, GeekFlare. Beginning to construct the App.
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Take a look at)
[Pipeline] enter
Do you wish to proceed?
Proceed or Abort
Accepted by geekflare
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] parallel
[Pipeline] { (Department: Deploy begin )
[Pipeline] { (Department: Deploying now)
[Pipeline] stage
[Pipeline] { (Deploy begin )
[Pipeline] stage
[Pipeline] { (Deploying now)
[Pipeline] getContext
[Pipeline] isUnix
[Pipeline] sh
[Pipeline] echo
Begin the deploy ..
[Pipeline] }
+ docker examine -f . nginx
[Pipeline] // stage
[Pipeline] }

Error: No such object: nginx
[Pipeline] isUnix
[Pipeline] sh
+ docker pull nginx
Utilizing default tag: newest
newest: Pulling from library/nginx
8d691f585fa8: Pulling fs layer
5b07f4e08ad0: Pulling fs layer
abc291867bca: Pulling fs layer
abc291867bca: Verifying Checksum
abc291867bca: Obtain full
5b07f4e08ad0: Verifying Checksum
5b07f4e08ad0: Obtain full
8d691f585fa8: Verifying Checksum
8d691f585fa8: Obtain full
8d691f585fa8: Pull full
5b07f4e08ad0: Pull full
abc291867bca: Pull full
Digest: sha256:922c815aa4df050d4df476e92daed4231f466acc8ee90e0e774951b0fd7195a4
Standing: Downloaded newer picture for nginx:newest
[Pipeline] withDockerContainer
Jenkins doesn't appear to be operating inside a container
$ docker run -t -d -u 125:131 -w "/var/lib/jenkins/workspace/First Pipeline" -v "/var/lib/jenkins/workspace/First Pipeline:/var/lib/jenkins/workspace/First Pipeline:rw,z" -v "/var/lib/jenkins/workspace/First Pipeline@tmp:/var/lib/jenkins/workspace/First Pipeline@tmp:rw,z" -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** nginx cat
$ docker prime 3141793b98f315dc90a57d810068b8eedb6f62debafb9040de06635b558f2943 -eo pid,comm
[Pipeline] {
[Pipeline] echo
Docker Created
[Pipeline] }
$ docker cease --time=1 3141793b98f315dc90a57d810068b8eedb6f62debafb9040de06635b558f2943
$ docker rm -f 3141793b98f315dc90a57d810068b8eedb6f62debafb9040de06635b558f2943
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // parallel
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Prod)
[Pipeline] echo
App is Prod Prepared
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] Finish of Pipeline
Completed: SUCCESS

The Jenkins Pipeline above created a docker picture of Nginx. You possibly can confirm that by operating the command beneath. You possibly can see the Nginx docker picture can be listed.

geekflare@chef-bestnich:~$ docker picture ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx newest 540a289bab6c 2 weeks in the past 126MB
httpd newest 7d85cc3b2d80 2 months in the past 154MB
redis newest f7302e4ab3a8 2 months in the past 98.2MB
geekflare_mongodb newest 095d17727ca0 3 months in the past 325MB

Conclusion

I hope this offers you an concept of ​​the advantages of the Jenkins pipeline and tips on how to create one. The above is an easy demonstration and one of the best ways to study it’s by making an attempt to construct advanced pipelines.

Leave a Comment

porno izle altyazılı porno porno