Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Declarative Pipelines in Jenkins

In this hands-on lab we will be looking at Declarative Pipelines. Declarative style pipelines limit what is available to the user with a more strict and pre-defined structure, making it an ideal choice for simpler continuous delivery pipelines. We'll be building the Pipeline (Declarative) and ensuring that it has gone through the build stages as defined and provided a satisfactory Jenkins job result.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Published
Clock icon Jun 05, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Jenkins UI

    Once you access the Jenkins landing page, click New Item on the left side of the screen to proceed towards selecting the type of Jenkins job you want to create.

    Once the new page loads, click on Pipeline and in the input box give a name to your job, such as MyDeclarativePipeline.

    After selecting the type of job, Pipeline, and giving it a name, click on OK to proceed with configuring the job.

  2. Challenge

    Configuring a Jenkins Pipeline Job (Declarative Pipeline)

    On the new page which loads for configuring the pipeline job, scroll down to the Pipeline section and ensure that Pipeline Script is selected in the Definition drop-down. An input area should be visible. Copy the following body of text (which is basically in Groovy DSL format, a format understood by Jenkins) into the input area:

    pipeline {
        agent {
            docker { image 'linuxacademycontent/jenkins_pipelines' }
        }
        stages {
            stage('fetch') {
                steps {
                    sh 'git clone https://github.com/linuxacademy/content-pipelines-cje-labs.git'
                }
            }
            stage('build'){
                steps{
                    sh 'gcc --std=c99 -o mario content-pipelines-cje-labs/lab1_lab2/mario.c'
                }
            }
            stage('archive'){
                steps{
                    archiveArtifacts artifacts: 'mario'
                }
            }
        }
    }
    

    Leave everything else at the default settings and click on Save.

    Note: This Declarative Pipeline will pull down and run a Docker container which has git and gcc utilities installed for cloning and compiling the code.

  3. Challenge

    Running/Building Your Jenkins Declarative Pipeline Job

    After hitting Save in the previous step, you will be taken to the control page for the job you just configured. There you can see the job status and other job statistics, and you will be able to edit the configuration again.

    To kick off a build, click on Build Now. This should start the build, and you should see the output of build status in a couple of places on your current screen.

    Under the Build History box, on the left of your screen you'll see a build number, and a progress bar if the build is currently running. The page will also be updated with a Stage View, which gives details of execution success (green) and the time taken by each build stage that was defined in our Declarative Pipeline. Subsequent builds will add more data to average run times in the same area.

    If you click on the build number under Build History (#1 for example), you will be taken to the details of the specific build. This includes things like Console Output for showing the execution of commands defined in the pipeline for each step.

    On this page you'll also find the build output files, or Build Artifacts, which are the outcome of the pipeline stages that you built. You can click on the actual file name shown under build artifacts to download it to your system.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans