<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rodrigo Prates</title>
    <description>The latest articles on DEV Community by Rodrigo Prates (@rodrigocprates).</description>
    <link>https://dev.to/rodrigocprates</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F240282%2Febc19e28-d4f6-4699-a1d5-afa2157bed58.jpeg</url>
      <title>DEV Community: Rodrigo Prates</title>
      <link>https://dev.to/rodrigocprates</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rodrigocprates"/>
    <language>en</language>
    <item>
      <title>Code reuse with Jenkins Shared Libraries</title>
      <dc:creator>Rodrigo Prates</dc:creator>
      <pubDate>Thu, 21 Jul 2022 18:51:59 +0000</pubDate>
      <link>https://dev.to/rodrigocprates/code-reuse-with-jenkins-shared-libraries-4np9</link>
      <guid>https://dev.to/rodrigocprates/code-reuse-with-jenkins-shared-libraries-4np9</guid>
      <description>&lt;p&gt;Building pipelines for multiple projects, specially in a distributed architecture such as microservices, is more than normal in nowadays.&lt;/p&gt;

&lt;p&gt;One thing that can come up when you are managing multiple pipelines for different projects, is that you might have similar code that needs to run across all jobs. And you don't want to update one by one.&lt;/p&gt;

&lt;p&gt;For example, you could have a common function to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create git tags&lt;/li&gt;
&lt;li&gt;send Slack notifications&lt;/li&gt;
&lt;li&gt;run a tool to generate a report or scan for vulnerabilities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Jenkins gives the possibility to create a Shared Library that can be imported and reused across multiple jobs to avoid code duplication or silly maintenance.&lt;/p&gt;

&lt;p&gt;Here are the steps you need to make use of that in your CI/CD with Jenkins:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;create a repository to keep your shared library / common functions. see &lt;a href="https://github.com/rodrigocprates/jenkins-shared-library" rel="noopener noreferrer"&gt;https://github.com/rodrigocprates/jenkins-shared-library&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;setup the Shared Library through Jenkins configurations (/configure)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbl1a08yg2bu5x7fhmpde.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbl1a08yg2bu5x7fhmpde.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;update your Jenkinsfile to make use of it
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Library('jenkins-shared-library') _ // loads all library functions

stage('Demo') {
  common.sayHello("Rodrigo") // references 'common' as library 'common.groovy'
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever your job is triggered, it will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;clone this shared library repo (with most updated code)&lt;/li&gt;
&lt;li&gt;import the functions&lt;/li&gt;
&lt;li&gt;run whatever function you call in your pipeline&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;Easy and straight to the point!&lt;br&gt;
Here's the repo: &lt;a href="https://github.com/rodrigocprates/jenkins-shared-library" rel="noopener noreferrer"&gt;https://github.com/rodrigocprates/jenkins-shared-library&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setting up a Jenkins instance with Configuration as Code (using yaml configuration)</title>
      <dc:creator>Rodrigo Prates</dc:creator>
      <pubDate>Wed, 29 Jun 2022 18:55:39 +0000</pubDate>
      <link>https://dev.to/rodrigocprates/setting-up-a-jenkins-instance-with-configuration-as-code-using-yaml-configuration-3m4m</link>
      <guid>https://dev.to/rodrigocprates/setting-up-a-jenkins-instance-with-configuration-as-code-using-yaml-configuration-3m4m</guid>
      <description>&lt;p&gt;Sometimes we want to have visibility and keep track of how our Jenkins instance is configured and parameterized. &lt;/p&gt;

&lt;p&gt;Doing these changes from the &lt;em&gt;Jenkins UI&lt;/em&gt; is pretty straightforward, but in the other hand we don't keep track of history changes and we need to jump to one menu item to another to get the big picture of how the setup is as a whole.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/jenkinsci/configuration-as-code-plugin" rel="noopener noreferrer"&gt;According to &lt;em&gt;Jenkins Configuration as Code plugin&lt;/em&gt; docs:&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Configuration as Code plugin is an opinionated way to configure Jenkins based on human-readable declarative configuration files. Writing such a file should be feasible without being a Jenkins expert, just translating into code a configuration process one is used to executing in the web UI&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In another post we talked about &lt;a href="https://rodrigocprates.hashnode.dev/jenkins-pipeline-essentials" rel="noopener noreferrer"&gt;the importance of using a Jenkinsfile to keep track of all pipeline changes&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, we can still have the same approach to set up our &lt;em&gt;Jenkins instance&lt;/em&gt; with &lt;br&gt;
&lt;em&gt;Configuration as Code&lt;/em&gt;, meaning we define and declare all instance parameters and configurations and keep track of any changes made to our CI/CD tool.&lt;/p&gt;

&lt;p&gt;Let's see below how it can be done in practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use case
&lt;/h2&gt;

&lt;p&gt;Since we want a pretty simple Jenkins setup, let's:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;start a fresh Jenkins installation&lt;/li&gt;
&lt;li&gt;define some environment variables&lt;/li&gt;
&lt;li&gt;define a JDK tool installation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then we'll setup a Jenkins pipeline with a &lt;em&gt;Jenkinsfile&lt;/em&gt; that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;prints some environment variables&lt;/li&gt;
&lt;li&gt;runs &lt;em&gt;java --version&lt;/em&gt; to see the Java 11 version printed&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup a Jenkins instance
&lt;/h2&gt;

&lt;p&gt;To simplify (if you already have a Docker up and running), &lt;a href="https://hub.docker.com/r/jenkins/jenkins" rel="noopener noreferrer"&gt;start your Jenkins instance&lt;/a&gt;: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker pull jenkins/jenkins:lts-jdk11&lt;br&gt;
docker run -p 8080:8080 -p 50000:50000 --restart=on-failure jenkins/jenkins:lts-jdk11&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we are going to use &lt;a href="https://github.com/jenkinsci/configuration-as-code-plugin" rel="noopener noreferrer"&gt;Configuration as Code plugin&lt;/a&gt; and some other plugins. &lt;/p&gt;

&lt;p&gt;Go to &lt;em&gt;Manage Jenkins -&amp;gt; Manage Plugins -&amp;gt; Available&lt;/em&gt; and install the following plugins:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configuration as Code&lt;/li&gt;
&lt;li&gt;AdoptOpenJDK installer&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create you configuration files
&lt;/h2&gt;

&lt;p&gt;Now we need to declare the &lt;em&gt;configurations for our Jenkins *instance and also define *how our pipeline is going to work&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rodrigocprates/jenkins-configuration-as-code" rel="noopener noreferrer"&gt;You can create them in a public repository, like I'm doing here.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create your &lt;em&gt;Configuration as Code&lt;/em&gt; yaml file (Jenkins configs)
&lt;/h2&gt;

&lt;p&gt;It will define 2 new global environment vars on Jenkins and setup a JDK11 tool.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;jenkins:&lt;br&gt;
  systemMessage: "Jenkins instance using Configuration as Code."&lt;br&gt;
  globalNodeProperties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;envVars:
  env:

&lt;ul&gt;
&lt;li&gt;key: SOME_ENV_PATH
value: "/path/to/somewhere"&lt;/li&gt;
&lt;li&gt;key: AWS_REGION
value: us-west-2
tool:
jdk:
installations:

&lt;ul&gt;
&lt;li&gt;name: jdk11
home: "/jdk"
properties:

&lt;ul&gt;
&lt;li&gt;installSource:
installers:

&lt;ul&gt;
&lt;li&gt;adoptOpenJdkInstaller:
  id: "jdk-11.0.14+9"&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Create your &lt;em&gt;Jenkinsfile&lt;/em&gt; (Pipeline definition)&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;It will create two stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;print the variables we defined&lt;/li&gt;
&lt;li&gt;run the &lt;em&gt;java version&lt;/em&gt; command to print it's version&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;pipeline {&lt;br&gt;
  agent any&lt;br&gt;
  environment {&lt;br&gt;
    somePath = "${env.SOME_ENV_PATH}"&lt;br&gt;
    awsRegion = "${env.AWS_REGION}"&lt;br&gt;
  }&lt;br&gt;
  stages {&lt;br&gt;
    stage('Print my stuff') {&lt;br&gt;
      steps {&lt;br&gt;
        echo "somePath environment var is [${somePath}]"&lt;br&gt;
        echo "awsRegion environment var is [${awsRegion}]"&lt;br&gt;
      }&lt;br&gt;
    }&lt;br&gt;
    stage("Check JAVA version") {&lt;br&gt;
      steps {&lt;br&gt;
        sh "java --version"&lt;br&gt;
      }&lt;br&gt;
    }&lt;/p&gt;

&lt;p&gt;}&lt;br&gt;
  post {&lt;br&gt;
    always {&lt;br&gt;
      cleanWs()&lt;br&gt;
    }&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Using &lt;em&gt;Configuration as Code&lt;/em&gt; plugin&lt;br&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Updating your Jenkins configurations
&lt;/h3&gt;

&lt;p&gt;Whenever you want to update your configurations described on your &lt;em&gt;yaml&lt;/em&gt; file:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Update your &lt;em&gt;yaml&lt;/em&gt; file with the changes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Go to &lt;em&gt;Manager Jenkins -&amp;gt; Configuration as Code&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provide the path/URL to your &lt;em&gt;yaml file&lt;/em&gt; (in my case, that's the github raw url to the file)&lt;/li&gt;
&lt;li&gt;Click &lt;em&gt;Apply New Configuration&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;em&gt;View Configuration&lt;/em&gt; below to see the latest configs.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh02f8d1z0pj00og2e492.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh02f8d1z0pj00og2e492.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Run a pipeline
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;Pipeline&lt;/code&gt; job type pointing to a &lt;code&gt;Jenkinsfile&lt;/code&gt;(&lt;a href="https://github.com/rodrigocprates/jenkins-configuration-as-code/blob/main/Jenkinsfile" rel="noopener noreferrer"&gt;you can find the sample here&lt;/a&gt;):&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj7tf4g3stnzrjt07mrue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj7tf4g3stnzrjt07mrue.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When clicking on &lt;code&gt;Build&lt;/code&gt; you will see the respective &lt;em&gt;outputs&lt;/em&gt; on the &lt;code&gt;Console&lt;/code&gt; log:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Folgibi11jryy95wfekub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Folgibi11jryy95wfekub.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5wsgknlhddlfca1cbu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5wsgknlhddlfca1cbu9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;Making use of &lt;em&gt;Configuration as Code&lt;/em&gt; plugin definitely helps to keep track of any changes done to your Jenkins configurations and also gives visibiliy to everybody in your team/company.&lt;/p&gt;

&lt;p&gt;You can still setup more complex things (&lt;a href="https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos" rel="noopener noreferrer"&gt;as you can see some demos here&lt;/a&gt;) and also automate the way you update your Jenkins configurations (ironically, with a Jenkins pipeline).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feel free to check the files used for this exercise &lt;a href="https://github.com/rodrigocprates/jenkins-configuration-as-code" rel="noopener noreferrer"&gt;on my github repo here&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The essentials about CI/CD and GitOps enabled by a fancy Jenkinsfile</title>
      <dc:creator>Rodrigo Prates</dc:creator>
      <pubDate>Tue, 14 Jun 2022 19:29:09 +0000</pubDate>
      <link>https://dev.to/rodrigocprates/the-essentials-about-cicd-and-gitops-enabled-by-a-fancy-jenkinsfile-41g3</link>
      <guid>https://dev.to/rodrigocprates/the-essentials-about-cicd-and-gitops-enabled-by-a-fancy-jenkinsfile-41g3</guid>
      <description>&lt;p&gt;There are a lot of developers working in a daily basis pushing code and deploying it to different environments.&lt;br&gt;
Sometimes they don't even notice the details, but &lt;em&gt;how this code gets deployed&lt;/em&gt;? &lt;em&gt;how a pipeline looks like to deploy into different environments&lt;/em&gt;? &lt;em&gt;are we running enough code quality checks?&lt;/em&gt; &lt;em&gt;what are the steps taken to build and deploy it?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To get a broader vision about how it can be done (and it's just one way of doing it), let's clarify a little bit more about what Jenkins, CI/CD and GitOps are and how a Jenkins pipeline looks like.&lt;/p&gt;
&lt;h2&gt;
  
  
  Jenkins, CI/CD and GitOps
&lt;/h2&gt;

&lt;p&gt;As you probably know, &lt;a href="https://www.jenkins.io/"&gt;Jenkins is a very popular and complete tool&lt;/a&gt; for managing your builds, deployments and scripts related to you CI/CD process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.redhat.com/en/topics/devops/what-is-ci-cd"&gt;CI/CD stands for &lt;em&gt;continuous integration&lt;/em&gt; and &lt;em&gt;continuous delivery&lt;/em&gt;&lt;/a&gt; that aim to deliver frequent software to end customers. Think about your whole application lifecycle where you implement new features, run different levels of testing and quality code stuff (such as lints, static code analysis, etc) and then integrate this new code into different environments without breaking anything.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://about.gitlab.com/topics/gitops/"&gt;Now &lt;em&gt;GitOps&lt;/em&gt; comes tied together to the DevOps world&lt;/a&gt;, that brings the mindset of keeping on your Git/VCS all details about the actual &lt;em&gt;implementation&lt;/em&gt; of your processes (like your pipelines and automation scripts), with all versions history and the most updated implementation. &lt;br&gt;
Going beyond, it also enables collaboration, compliance and an automated way to provision your infrastructure based on the versioned scripts (just like we do for applications).&lt;/p&gt;

&lt;p&gt;Since we want to &lt;em&gt;keep track of all the changes and most updated version of our application pipeline&lt;/em&gt;, Jenkins enables that by allowing you to use a &lt;em&gt;Jenkinsfile&lt;/em&gt; to define each step taken from build to deploy.&lt;/p&gt;
&lt;h2&gt;
  
  
  A simple and effective example of how a &lt;em&gt;Jenkinsfile&lt;/em&gt; looks like
&lt;/h2&gt;

&lt;p&gt;Putting in simple words, by using a Jenkinsfile you will have &lt;strong&gt;flexibility to write all logic needed with declarative/scripted pipelines&lt;/strong&gt; and mostly keep a &lt;strong&gt;single source of truth about how your deployments and CI/CD looks like&lt;/strong&gt; with all history of changes of it.&lt;/p&gt;

&lt;p&gt;As you can see below, there's no magic about how this pipeline is going to work. &lt;br&gt;
It implicitly uses Jenkins pre-configured items like &lt;strong&gt;tools&lt;/strong&gt;, &lt;strong&gt;AWS environment variables&lt;/strong&gt;, a default &lt;strong&gt;maven&lt;/strong&gt; installation (&lt;em&gt;mvn&lt;/em&gt; command) and that's it.&lt;br&gt;
Other than that, you can see each &lt;em&gt;Stage&lt;/em&gt; and all it's &lt;em&gt;Steps&lt;/em&gt; taken to run from end-to-end. There are no hidden details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any
    options {
        timeout(time: 10, unit: 'MINUTES') // you can set a global pipeline timeout
    }
    tools {
        jdk "jdk8" // you can use pre-configured Jenkins tools
    }
    environment {

        // using pre-configured Jenkins environment variables
        awsKey = "${env.AWS_ACCESS_KEY_ID}"
        awsSecretKey = "${env.AWS_SECRET_ACCESS_KEY}"
        awsRegion = "${env.AWS_DEFAULT_REGION}"

        isDevEnvironment = true
        shouldCreateTag = false
    }

    stages {
        stage('Initialize') {
            steps {
                script {
                    isBranchValid = ['master', 'feature/', 'hotfix/', 'bugfix/'].any { standard_branch -&amp;gt; env.BRANCH_NAME.startsWith(standard_branch) }
                    if (!is_branch_valid) {
                        error("You couldn't have a branch named like that!")
                    }
                }
            }
        }
        stage('Build') {
            options {
                timeout(time: 5, unit: 'MINUTES') // you can set a stage specific timeout
            }
            steps {
                sh 'mvn clean package -DskipTests -U'
            }
        }
        stage("Unit Tests") {
            steps {
                sh "mvn test"
            }
        }
        stage('Create tag') {
            when {
                expression { return env.shouldCreateTag }
            }
            steps {
                nextTag = createTag()
                echo "Created tag as [${nextTag}]!"
            }
        }
        stage("Deploy DEV") {
            when {
                expression { return env.isDevEnvironment }
            }
            steps {
                echo "Deploying to DEV..."
                deploy()
            }
        }

    }
    post {
        always {
            cleanWs() // post.always will run at the end
        }
    }
}

Boolean deploy() {
    // do some logic to deploy..
}

String createTag() {
    // logic to create a new Git tag..
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, &lt;strong&gt;you will link your new Jenkins job to read the &lt;em&gt;Jenkinsfile&lt;/em&gt; in your git repository&lt;/strong&gt;, and then it will be turned in your actual pipeline:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZmoPOBQV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ab3bgqtvt7bvey8wbn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZmoPOBQV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ab3bgqtvt7bvey8wbn9.png" alt="Image description" width="880" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;There are plenty talks, sample code and walkthroughs over the internet about how you can setup your Jenkins pipelines. It comes down to first understanding what are the problems you are trying to solve and go for it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.jenkins.io/doc/book/pipeline/"&gt;Jenkins pipeline documentation&lt;/a&gt; is a great place to go deeper over details like &lt;em&gt;pipeline syntax&lt;/em&gt;, &lt;em&gt;declarative vs scripted pipelines&lt;/em&gt;,  &lt;em&gt;best practices&lt;/em&gt; and much more.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;&lt;a href="https://rodrigocprates.hashnode.dev/jenkins-pipeline-essentials"&gt;&lt;em&gt;This was first posted by me on Hashnode tech blogging platform&lt;/em&gt;.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
