Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
Skills:
CI/CD Pipelines80%
Key Takeaways
Explains Jenkinsfile pipeline syntax and usage
Full Transcript
let's go ahead and create a Jenkins file in dev branch and I'm gonna do that using the get UI so let's go to dev and I'm gonna create a new file and this is the most basic Jenkins file that basically does nothing but this is the basic syntax we're going to go through a Jenkins file syntax in more detail in a later section but here I'm gonna explain you the required attributes for Jenkins file so the first thing is that Jenkins file can be written as a scripted pipeline or a declarative pipeline so the scripted pipeline was the first syntax of Jenkins file so what it is is basically it allows to write the whole configuration of the Jenkins file using groovy script so the only structure that you have there is this here and inside of this is basically groovy scripts and you can write the whole configuration here in a flexible manner as you wish so there is no predefined structure there however for people who didn't know or doesn't know groovy syntax or who hasn't worked with groovy is little bit difficult to start with that's why as a recent addition they actually edit declarative pipeline syntax from Jenkins file which is easier to get started with it has of course it's not as powerful as the scripted pipeline because here you're not limited in any way but it's easier to get started with because you have a predefined structure so this what you see here is basically pre given structure that you have to follow but again you don't have to think about how to script all this so you just fill in the gaps so what we saw here the note definition is basically same as these two lines here so in a declarative pipeline you declare that you are writing a pipeline and agent any basically means that this build is gonna run on any available Jenkins agent and agent can be a note it could be executors on that note whatever and this is more relevant when you have a Jenkins cluster so to say with master and slaves where you have Windows nodes and Linux nodes etc but here for the beginning for base we just say agent any so we'll just run with the next available agent and as I said these two are equivalent to this one here and they are required attributes you always have to use them the next required attribute is stages and this is where the whole work actually happens so you have different stages of that pipeline and inside the stages you define stage name and you can define as many stages as you want usually you have something like this so you have a build stage let's get rid of this one actually have a build stage maybe you have a test stage and then you have a deploy stage like this you can have additional ones like for example you might have a check out stage stage here and I don't know cleanup stage afterwards whatever and as you see inside the stage you have the steps and here goes the script that actually executes some comment on the Jenkins server or Jenkins agent so for example if you're building a JavaScript application all the NPM install NPM build etc scripts will go here like this if you are you know running tests or for Java back-end all the text execution scripts will be here and the deployment script will be here so right now let's just write simple echo comments to kind of test this so here we're gonna say building the application and here we're gonna say testing the application in here we are deploying the application and this is a very Jenkins file and this should work already so let's actually now we committed it and let's go back to our pipeline and let's scan it again and see the locks and it's doing something so as you see here it found Jenkins file in dev and now it's actually executing the Jenkins file right here so if I go back to my pipeline view I already see the first branch was built and that's a dev branch let's go inside and see the first execution so what happened here the first step that you see is check out the code the second one was built test deploy and here you can see the logs and this is what we echoed in each stage testing the application etc so now the question is where did this come from so this stage is something we didn't define before and it basically checks out the code so how does this happen this actually comes from let's go back to my pipeline and configure this actually comes from this one right here so by defining or by configuring that we want git repository with this URL to be checked out we basically in UI declaring that we want that checkout stage to happen right so it automatically adds to the pipeline stage now you could do that in your Jenkins file instead of configuring it in the pipeline configuration but I actually prefer to have that step configured in the pipeline you eye configuration so this is the result of Jenkins file execution and here inside of that branch configuration you also have some options like where you can build the branch manually and see the configuration but at this point it's important to note that most of the configuration will be done in Jenkins file or on the pipeline level in the configure mask so right here and not on the individual branch level so you wouldn't be doing anything here that's why you can only see the configuration but not edit the configuration so now what if you want to test some stuff or some changes in a Jenkins file let's say add one of the steps you want to test some groovy expression and you are new to groovy so you're just learning and you just want to try this out and it will be more effort to you know adjust the Jenkins filed and commit it and you know it has to check out again the changes and rebuild it again etc so there is actually a handy way to do that in Jenkins so we can test and execute the Jenkins file changes without having to commit each change so the way to do that is go to one of the branches so let's say in the dev and here you have the history of the build and if you click inside one of those builds and here you have a bunch of options and one of them is replay and what replay does is basically allows you to adjust the last run jenkins file and rerun it again so here let's say i want to try some groovy expression so the thing is in this inside the steps you can only write the command line comments so if you want to try it or if you want to execute groovy script then you have to enclose it inside script so script will be one of the steps so here you can have echo I delete it again so building the application and inside script we can write some groovy expression so let's say let's just write something whatever so if this is true then we're gonna say cool if not no not cool and then I'm gonna echo this and let's run okay so it's building now and here if I open this I see filling the application and the new message so when now we tested the changes in the Jenkins file without having to actually commit it to the repository another thing that you can do with the specific build is also so if you click on this triangle you actually see all this commands as well replace there but you can also do restart from stage so if you click here you see a list a drop down list of all the stages that you have defined so if one of the stages fails or I don't know you need to repeat this stage again you can actually choose one of the stages without having to repeat all the other so let's actually choose the deploy and if I run in again you see you will skip the previous stages and just do the last one which also could be pretty handy sometimes
Original Description
Jenkinsfile Pipeline Tutorial. Learn about Jenkinsfile, the pipeline as code.
In this video I show the syntax of a Jenkinsfile, explain the differences between scripted and declarative syntax. I also show how to test something out in a Jenkinsfile by replaying it and how to skip stages via restart option.
▬▬▬▬▬▬ Topics covered
* Pipeline Syntax: Scripted vs. Declarative
* Basic Syntax
* Test something in Jenkinsfile - Replay Jenkinsfile
* Restart from stage
This is the 3rd part of a complete jenkins tutorial for beginners:
1) Run Jenkins in a Docker Container
2) Create Multibranch Pipeline with Git
3) Basic Jenkinsfile Syntax
4) Git Integration - Trigger Jenkins build automatically
⭐️Full Playlist: https://www.youtube.com/playlist?list=PLy7NrYWoggjw_LIiDK1LXdNN82uYuuuiC
For any questions/issues/feedback, please leave me a comment and I will get back to you as soon as possible.
#devops #jenkins #docker #techworldwithnana #devopstools
-------------------------------------------------------------------------------------------------------
Complete Docker and Kubernetes tutorial ► https://bit.ly/2YGeRp9
What is Kubernetes? ► https://youtu.be/VnvRFRk_51k
Docker 🐳 vs Kubernetes ► https://youtu.be/9_s3h_GVzZc
Complete Jenkins Pipeline Tutorial ► https://youtu.be/7KCS70sCoK0
--------------------------------------------------------------------------------------------------------
✅ Connect with me
Youtube ► https://www.youtube.com/channel/UCdngmbVKX1Tgre699-XLlUA
DEV ► https://dev.to/techworld_with_nana
Instagram ► https://www.instagram.com/techworld_with_nana/
Twitter ► https://twitter.com/Njuchi_/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from TechWorld with Nana · TechWorld with Nana · 26 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
▶
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What is Docker? Docker container concept explained || Docker Tutorial 1
TechWorld with Nana
What is a Docker Container? Docker Demo || Docker Tutorial 2
TechWorld with Nana
How to install docker? Step by Step || Docker Tutorial 3
TechWorld with Nana
8 Basic Docker Commands || Docker Tutorial 4
TechWorld with Nana
Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
TechWorld with Nana
Docker vs Virtual Machine | simply explained || Docker Tutorial 6
TechWorld with Nana
Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
TechWorld with Nana
Developing with Docker - Docker in Practice || Docker Tutorial 8
TechWorld with Nana
Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
TechWorld with Nana
Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
TechWorld with Nana
Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
TechWorld with Nana
Docker Volumes explained in 6 minutes
TechWorld with Nana
Deploying the containerized application with Docker Compose || Docker Tutorial 12
TechWorld with Nana
Docker Volumes Demo || Docker Tutorial 13
TechWorld with Nana
Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
TechWorld with Nana
What is Kubernetes | Kubernetes explained in 15 mins
TechWorld with Nana
Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
TechWorld with Nana
Kubernetes Architecture explained | Kubernetes Tutorial 15
TechWorld with Nana
Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
TechWorld with Nana
Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
TechWorld with Nana
Top 3 programming languages to learn in 2020 | meta analysis
TechWorld with Nana
Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
TechWorld with Nana
Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
TechWorld with Nana
Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
TechWorld with Nana
Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
TechWorld with Nana
Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
TechWorld with Nana
Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
TechWorld with Nana
Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
TechWorld with Nana
Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
TechWorld with Nana
Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
TechWorld with Nana
Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
TechWorld with Nana
Kubernetes Ingress Tutorial for Beginners | simply explained | Kubernetes Tutorial 22
TechWorld with Nana
What is Helm in Kubernetes? Helm and Helm Charts explained | Kubernetes Tutorial 23
TechWorld with Nana
How Websites Work | simply explained with examples
TechWorld with Nana
What is JavaScript? | JavaScript Tutorial #1
TechWorld with Nana
What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
TechWorld with Nana
JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
TechWorld with Nana
How Prometheus Monitoring works | Prometheus Architecture explained
TechWorld with Nana
Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
TechWorld with Nana
JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
TechWorld with Nana
Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
TechWorld with Nana
Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
TechWorld with Nana
Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
TechWorld with Nana
Pull Image from Private Docker Registry in Kubernetes cluster | Demo
TechWorld with Nana
Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
TechWorld with Nana
Yaml Tutorial | Learn YAML in 18 mins
TechWorld with Nana
Terraform explained in 15 mins | Terraform Tutorial for Beginners
TechWorld with Nana
Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
TechWorld with Nana
Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
TechWorld with Nana
Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
TechWorld with Nana
Kubernetes Operator simply explained in 10 mins
TechWorld with Nana
What is Infrastructure as Code? Difference of Infrastructure as Code Tools
TechWorld with Nana
AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
TechWorld with Nana
Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
TechWorld with Nana
GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
TechWorld with Nana
Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
TechWorld with Nana
Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
TechWorld with Nana
Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
TechWorld with Nana
Containers on AWS Overview: ECS | EKS | Fargate | ECR
TechWorld with Nana
Kubernetes is dropping Docker support - What does it mean for YOU?
TechWorld with Nana
More on: CI/CD Pipelines
View skill →Related Reads
📰
📰
📰
📰
Your monitoring cannot tell broken from off. Mine could not either.
Dev.to AI
AWS Self-Healing Infrastructure: Catching and Fixing Server Crashes with AI Autopilot
Medium · DevOps
Understanding a Real AWS CodePipeline CI/CD Flow: Source Build Deploy"
Dev.to · Guna SantoshDeep Srivastava
How to Use Terraform with Python for Infrastructure
Dev.to · qing
🎓
Tutor Explanation
DeepCamp AI