Understanding Jenkins Pipelines - part 2
Hello again and welcome back to my blog! If you are here, I trust that you have gone through the basics of Jenkins Pipelines outlined in Understanding Jenkins Pipelines - Part 1. In this blog post, we will look at how you can build you own pipeline script using the fundamentals and some resources.
Build your own pipeline
Create a new Jenkins Pipeline job by selecting the pipeline job as follows.
Once you have created the pipeline job, save the job without modifying anything in the configuration for now.
From the menu bar, select 'Configure' on one tab, and navigate to the pipeline script section.
In a separate tab, navigate back to the menu bar of the job and select 'Pipeline Syntax'.
In the 'Pipeline Syntax' page, you will see options of Snippet Generator and Declarative Directive Generator.
These two options will allow you to graphically select the steps aspects that you want to include in your pipeline script and can generate the pipeline code snippet that you can include in your pipeline script. Be sure to use one of the fundamental script types as outlined in Understanding Jenkins Pipelines - Part 1.
Snippet Generator
As per Jenkins, the Snippet Generator will help you learn the Pipeline Script code which can be used to define various steps. Pick a step you are interested in from the list, configure it, click Generate Pipeline Script, and you will see a Pipeline Script statement that would call the step with that configuration. You may copy and paste the whole statement into your script, or pick up just the options you care about. (Most parameters are optional and can be omitted in your script, leaving them at default values.)
Declarative Directive Generator
As per Jenkins, the Directive Generator allows you to generate the Pipeline code for a Declarative Pipeline directive, such as agent, options, when, and more. Choose the directive you're interested in from the dropdown, and then choose the contents of the directive from the new form. Once you've filled out the form with the choices and values you want for your directive, click Generate Declarative Directive and the Pipeline code will appear in the box below. You can copy that code directly into the pipeline block in your Jenkinsfile, for top-level directives, or into a stage block for stage directives. See the online syntax documentation for more information on directives.
Note: I would also recommend cehckout out your own organizations jenkins pipline examples!
Thats all for this blog post. I hope that you learned something new! ☺️