Skip to content

Latest commit

 

History

History
143 lines (84 loc) · 6.12 KB

Step5.md

File metadata and controls

143 lines (84 loc) · 6.12 KB

click here to go back to the main README.

Step 5 - Create pipeline with all jobs

Table of Contents


Introduction

In this step we are introducing two topics:

  • Build (job) Triggers
  • Chaining Jobs / Projects in a pipeline.

Here we get to the nitty gritty of things. In the past 4 steps we created the separate jobs we use in our Continuous Integration cycle. There's one caveat thought. As a developer or ops you don't have time to start each job whenever you process a commit on your code.

As Jenkins is an Automation tool after all we would like to proces all these job at once, preferably when new code is committed to the repository or in Daily / Nightly builds.

Build Triggers (or Scheduling)

Build Triggers are important in automation because they initiate the first step in kicking off a chain of jobs or a pipeline.

In jenkins there are three types of triggers:

  • Build Trigger -> available in a Job / pipeline to specify when the build step should start
  • Post Build Actions -> Avaliable in a Job only and specifies a follow-up action after build has taken place (see Step4).
  • scheduled trigger -> Available in a Job to specify an interval / schedule which the job should follow.

In our bootcamp we will build two triggers:

  • Upstream Trigger on Git to start the "Checkout Code" Job
  • Upstream Trigger on our pipeline (built later) to watch when "Checkout Code" has finished

note on terminology: Upstream is when a project / Pipeline executes a separate Project / Pipeline as part of its execution whereas a Downstream trigger is the Executed Project / Pipeline from another Project / Pipeline.

Upstream Trigger on Git to start the "Checkout Code" Job

In order for the trigger to work we need to reconfigure our "Code Checkout" Job

  • Open the "Code Checkout" Job
  • Go to the tab "Build triggers"

alt text

  • Select "Poll SCM" and Enter "* * * * *" as Value. This will poll SCM every minute. If you want a different value use another CRON Expression
  • Click "Save"

A better way to trigger this job is to listen to Git Commits done when Git pushes the Git Command. This Requires the Git Plugin version 1.1.14 and an alteration to your local git. Use this guide to set it up. Use at your own risk!

alt text

Try your new trigger by pushing code to the remote repository and see if the "Code Checkout" job starts.

Upstream Trigger on our pipeline (built later) to watch when "Checkout Code" has finished

We will configure this during the construction of our Pipeline.

Manual Pipeline

Constructing Pipelines in jenkins is done in the Groovy language and stored in a Jenkinsfile which is to be stored in the code repository so it can be used upon code checkout.

A jenkinsfile will follow a set of instructions to configure Stages, Steps, Parameters etc.

The jenkinsfile starts with a pipeline{} command along with the specification of a specific or any agent.

#!groovy

pipeline {
    agent any

}

Within this syntax follow various stages{} , stage('name'){} and steps{} commands to specify what needs to be done in the pipeline.

We are going to create our first "Manual Pipeline" Pipeline.

  • Go back to your Jenkins Dashboard if not already there.
  • Go to "New item". Enter “Manual Pipeline” as the item name and choose "Pipeline"

alt text

alt text

  • in The Build Triggers tab check "Build after other projects are built" and choose "Code Checkout"

alt text

You can play with the check marks to see the difference.

  • in the Pipeline tab under Definition select "Pipeline Script"

alt text

  • write code to create a pipeline with the 3 remaining stages (steps) with each one step using the "build job:'name'" command.
  • click "Save"

need help creating pipeline syntax?

either click on pipeline syntax in the configure screen or check this link: http://localhost:8080/job/Manual%20Pipeline/pipeline-syntax/

Push a change to your Remote repo to fire off the "Code Checkout" job which will start the pipeline for the remaining

go to the pipeline and select "Stage view" to get a visual representation of the view.

alt text

Jenkinsfile Pipeline

to further automate the building process specific to the code you want to automate we may want to run different jobs or in a different order.

  • The code you have written could be saved in a "Jenkinsfile" and stored along with the rest of the code. an Empty example can be found in the Sourcecode folder.
  • Go back to your Jenkins Dashboard if not already there.
  • Go to "New item". Enter "Jenkinsfile Pipeline” as the item name and choose "Pipeline"
  • to use this script in the pipeline select "pipeline script from SCM" in the pipeline

alt text

  • add the git remote repository
  • Select the appropriate branch
  • In path leave the setting to Jenkinsfile to search the root of the repository

If you are having troubles getting your Jenkinsfile working you can point the SCM to "*/step5"

alt text

Have a look at that super shiny awesome looking pipeline you just created. yes.... you may pat yourself on the back ^^


Back to top

click here to go back to the main README.