Declarative and Scripted pipeline job in Jenkins -PART 2

Share via:

Please check the PART -1, before going through the Part -2

Declarative and Scripted pipeline job in Jenkins -PART 1

🔗https://www.ktexperts.com/declarative-and-scripted-pipeline-job-in-jenkins-part-1/

 

Declarative and Scripted pipeline job in Jenkins -PART 2

Creating a Scripted Pipeline job (code in Jenkins web UI):
👉 Configure the Jenkins job for scripted pipeline ->

👉 Write the code in the Jenkins Web UI ->
👉 Build the Job ->
👉 Check the Job output->

Creating a Pipeline job using Jenkins file – (code using Jenkins file in Repo):
👉 Copy the repository URL GITHUB ->
👉 Create the Jenkins file (with code) in GITHUB Repo ->
👉 Copy the Jenkins file URL from GITHUB->
👉 Configure the Jenkins job with Jenkins file option ->
👉 Build the Jenkins job ->                                                                     
👉 Check the job output   ->                                                                     
Option ->Checking Pipeline Steps -Individual steps
Snipper Generator – Help/guide to generate Pipeline script.
Sandbox Security option in Jenkins
This is option is for Restricted Access
▪️ Jenkins limits the execution of any Groovy script by providing a sandbox.
▪️ The option “Use Groovy Sandbox,” shown below, is available in the Pipeline tab, and it allows the scripts to be run by any user without requiring administrator privileges.
▪️ In this case, the script is run only by using the internal accessible APIs (which allow you to develop your script by using Groovy).
▪️ When unchecked, if the script has operations that require approval, an administrator will have to provide them. This method is known as “Script approval.” By default, all Jenkins pipelines run in a Groovy sandbox.
▪️ If the option is checked and unauthorized operations are used, the script will fail when run.
What to choose between two – Declarative (or) Scripted?
▪️ Scripted vs. declarative pipelines are different only in their programmatic approach.
▪️ One uses a declarative programming model, while the other uses an imperative programming model.
▪️ What about the choice between declarative vs. scripted pipelines for a new project?
▪️ The answer to that question is most definitely the declarative pipeline.
▪️ The development industry has largely moved toward a declarative programming model for CI/CD pipelines.
▪️ Both GitHub Actions and GitLab CI support only YAML pipelines, which are very similar to declarative Jenkins pipelines.
▪️ Furthermore, declarative pipelines are easier to maintain, and they tend to have a lower learning curve.
▪️ Though both these pipelines are based on the groovy DSL, the scripted pipeline uses stricter groovy based syntaxes because it was the first pipeline to be built on the groovy foundation.
▪️ Since this Groovy script was not typically desirable to all the users, the declarative pipeline was introduced to offer a simpler and more optioned Groovy syntax.
▪️ Declarative pipeline is a relatively new feature that supports the pipeline as code concept. It makes the pipeline code easier to read and write. This code is written in a Jenkins file which can be checked into a source control management system such as Git.
▪️ Whereas the scripted pipeline is a traditional way of writing the code. In this pipeline, the Jenkins file is written on the Jenkins UI instance.
▪️ The declarative pipeline is defined within a block labelled ‘pipeline’ whereas the scripted pipeline is defined within a ‘node’
▪️ The declarative syntax is the best approach to use when new CI/CD workflows are built.

 

Author    : Venkat Vinod Kumar Siram 
LinkedIn : https://www.linkedin.com/in/vinodsiram/
Assisted by Shanmugavel
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates.
KTExperts is always active on social media platforms.
Facebook  : https://www.facebook.com/ktexperts
LinkedIn    : https://www.linkedin.com/company/ktexperts/
Twitter       : https://twitter.com/ktexpertsadmin
YouTube   :  https://www.youtube.com/c/ktexperts
Instagram  : https://www.instagram.com/knowledgesharingplatform
Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Add Comment